@merkl/api 0.10.362 → 0.10.378
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/README.md +78 -14
- package/dist/database/api/.generated/edge.js +21 -6
- package/dist/database/api/.generated/index-browser.js +18 -3
- package/dist/database/api/.generated/index.d.ts +1746 -256
- package/dist/database/api/.generated/index.js +21 -6
- package/dist/database/api/.generated/package.json +1 -1
- package/dist/database/api/.generated/schema.prisma +12 -2
- package/dist/database/api/.generated/wasm.js +18 -3
- package/dist/src/eden/index.d.ts +1041 -140
- package/dist/src/entities/campaign.js +2 -1
- package/dist/src/entities/opportunity.js +169 -3
- package/dist/src/index.d.ts +340 -9
- package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicData.js +45 -54
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType.d.ts +3 -1
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType.js +4 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/ERC4626Processor.d.ts +34 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/ERC4626Processor.js +36 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/processorMapping.js +3 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/subtypesRound1.js +4 -1
- package/dist/src/libs/campaigns/campaignTypes/HyperdriveDynamicData.d.ts +5 -0
- package/dist/src/libs/campaigns/campaignTypes/HyperdriveDynamicData.js +76 -0
- package/dist/src/libs/campaigns/campaignsDynamicData.js +8 -0
- package/dist/src/modules/v4/campaign/campaign.controller.d.ts +2 -0
- package/dist/src/modules/v4/campaign/campaign.model.d.ts +1 -0
- package/dist/src/modules/v4/campaign/campaign.model.js +1 -0
- package/dist/src/modules/v4/campaign/campaign.repository.d.ts +63 -1
- package/dist/src/modules/v4/campaign/campaign.repository.js +15 -10
- package/dist/src/modules/v4/computedValue/computedValue.controller.d.ts +7 -4
- package/dist/src/modules/v4/computedValue/computedValue.controller.js +7 -5
- package/dist/src/modules/v4/computedValue/computedValue.model.js +12 -4
- package/dist/src/modules/v4/computedValue/computedValue.repository.d.ts +8 -5
- package/dist/src/modules/v4/computedValue/computedValue.repository.js +7 -3
- package/dist/src/modules/v4/computedValue/computedValue.service.d.ts +7 -4
- package/dist/src/modules/v4/computedValue/computedValue.service.js +10 -0
- package/dist/src/modules/v4/creator/creator.controller.d.ts +118 -0
- package/dist/src/modules/v4/creator/creator.controller.js +30 -0
- package/dist/src/modules/v4/creator/creator.model.d.ts +29 -0
- package/dist/src/modules/v4/creator/creator.model.js +18 -0
- package/dist/src/modules/v4/creator/creator.repository.d.ts +40 -0
- package/dist/src/modules/v4/creator/creator.repository.js +63 -0
- package/dist/src/modules/v4/creator/creator.service.d.ts +61 -0
- package/dist/src/modules/v4/creator/creator.service.js +44 -0
- package/dist/src/modules/v4/creator/index.d.ts +3 -0
- package/dist/src/modules/v4/creator/index.js +3 -0
- package/dist/src/modules/v4/dynamicData/dynamicData.controller.d.ts +3 -4
- package/dist/src/modules/v4/dynamicData/dynamicData.controller.js +1 -1
- package/dist/src/modules/v4/dynamicData/dynamicData.model.d.ts +1 -0
- package/dist/src/modules/v4/dynamicData/dynamicData.model.js +1 -0
- package/dist/src/modules/v4/dynamicData/dynamicData.service.d.ts +6 -3
- package/dist/src/modules/v4/dynamicData/dynamicData.service.js +50 -9
- package/dist/src/modules/v4/opportunity/opportunity.controller.d.ts +171 -1
- package/dist/src/modules/v4/opportunity/opportunity.controller.js +14 -0
- package/dist/src/modules/v4/opportunity/opportunity.model.d.ts +0 -1
- package/dist/src/modules/v4/opportunity/opportunity.repository.d.ts +185 -0
- package/dist/src/modules/v4/opportunity/opportunity.repository.js +41 -0
- package/dist/src/modules/v4/opportunity/opportunity.service.d.ts +151 -1
- package/dist/src/modules/v4/opportunity/opportunity.service.js +45 -2
- package/dist/src/modules/v4/opportunity/subservices/getHyperdriveMetadata.service.d.ts +1 -1
- package/dist/src/modules/v4/opportunity/subservices/getHyperdriveMetadata.service.js +2 -2
- package/dist/src/modules/v4/programPayload/programPayload.controller.d.ts +30 -0
- package/dist/src/modules/v4/programPayload/programPayload.controller.js +12 -1
- package/dist/src/modules/v4/programPayload/programPayload.model.d.ts +21 -1
- package/dist/src/modules/v4/programPayload/programPayload.model.js +12 -0
- package/dist/src/modules/v4/programPayload/programPayload.repository.d.ts +13 -2
- package/dist/src/modules/v4/programPayload/programPayload.repository.js +230 -83
- package/dist/src/modules/v4/programPayload/programPayload.service.d.ts +2 -1
- package/dist/src/modules/v4/programPayload/programPayload.service.js +42 -2
- package/dist/src/modules/v4/protocol/protocol.controller.d.ts +1 -0
- package/dist/src/modules/v4/protocol/protocol.model.d.ts +1 -0
- package/dist/src/modules/v4/protocol/protocol.model.js +1 -0
- package/dist/src/modules/v4/reward/reward.repository.d.ts +2 -1
- package/dist/src/modules/v4/reward/reward.repository.js +12 -1
- package/dist/src/modules/v4/reward/reward.service.js +5 -2
- package/dist/src/modules/v4/router.d.ts +340 -9
- package/dist/src/modules/v4/router.js +3 -1
- package/dist/src/modules/v4/user/user.controller.d.ts +28 -0
- package/dist/src/modules/v4/user/user.controller.js +5 -0
- package/dist/src/modules/v4/user/user.repository.d.ts +5 -0
- package/dist/src/modules/v4/user/user.service.d.ts +5 -0
- package/dist/src/utils/decodeCalls.js +7 -1
- package/dist/src/utils/encodeCalls.js +19 -1
- package/dist/src/utils/generateCardName.js +3 -0
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +6 -2
@@ -1,13 +1,16 @@
|
|
1
1
|
import type { GetCampaignComputedValueModel, GetUserComputedValuesModel, UpsertCampaignComputedValueModel, UpsertUserComputedValuesModel } from "./computedValue.model";
|
2
2
|
export declare class ComputedValueService {
|
3
3
|
static findCampaignValue(params: GetCampaignComputedValueModel): Promise<{
|
4
|
-
|
5
|
-
|
4
|
+
averageBoost: number | null;
|
5
|
+
totalDistributedInUSD: number | null;
|
6
|
+
forfeitingBoost: number | null;
|
6
7
|
} | null>;
|
7
8
|
static upsertCampaignComputedValue(data: UpsertCampaignComputedValueModel): Promise<void>;
|
8
9
|
static findUserValues(params: GetUserComputedValuesModel): Promise<{
|
9
|
-
|
10
|
-
|
10
|
+
reason: string;
|
11
|
+
id: number;
|
12
|
+
campaignId: string;
|
13
|
+
boost: number | null;
|
11
14
|
}[]>;
|
12
15
|
static upsertUserComputedValues(data: UpsertUserComputedValuesModel): Promise<void>;
|
13
16
|
}
|
@@ -1,6 +1,15 @@
|
|
1
|
+
import { log } from "../../../utils/logger";
|
2
|
+
import { CampaignService } from "../campaign";
|
1
3
|
import { ComputedValueRepository } from "./computedValue.repository";
|
2
4
|
export class ComputedValueService {
|
3
5
|
static async findCampaignValue(params) {
|
6
|
+
if (params.campaignId.includes("-") && params.campaignId.startsWith("0x")) {
|
7
|
+
const [campaignId, distributionChain] = params.campaignId.split("-");
|
8
|
+
params.campaignId = CampaignService.hashId({ campaignId, distributionChain: Number.parseInt(distributionChain) });
|
9
|
+
}
|
10
|
+
else if (params.campaignId.startsWith("0x")) {
|
11
|
+
params.campaignId = (await CampaignService.findMany({ campaignId: params.campaignId }))[0].id;
|
12
|
+
}
|
4
13
|
return await ComputedValueRepository.findCampaignValue(params);
|
5
14
|
}
|
6
15
|
static async upsertCampaignComputedValue(data) {
|
@@ -11,5 +20,6 @@ export class ComputedValueService {
|
|
11
20
|
}
|
12
21
|
static async upsertUserComputedValues(data) {
|
13
22
|
await ComputedValueRepository.upsertUserComputedValues(data);
|
23
|
+
log.info(`Upserted ${data.length} users computed values`);
|
14
24
|
}
|
15
25
|
}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import { Elysia } from "elysia";
|
2
|
+
export declare const CreatorController: Elysia<"/creators", false, {
|
3
|
+
decorator: {};
|
4
|
+
store: {};
|
5
|
+
derive: {};
|
6
|
+
resolve: {};
|
7
|
+
}, {
|
8
|
+
type: {};
|
9
|
+
error: {};
|
10
|
+
}, {
|
11
|
+
schema: {};
|
12
|
+
macro: {};
|
13
|
+
macroFn: {};
|
14
|
+
}, {
|
15
|
+
creators: {
|
16
|
+
index: {
|
17
|
+
get: {
|
18
|
+
body: unknown;
|
19
|
+
params: {};
|
20
|
+
query: {
|
21
|
+
items?: number | undefined;
|
22
|
+
page?: number | undefined;
|
23
|
+
address?: string | undefined;
|
24
|
+
};
|
25
|
+
headers: unknown;
|
26
|
+
response: {
|
27
|
+
200: ({
|
28
|
+
name: string;
|
29
|
+
id: string;
|
30
|
+
addresses: string[];
|
31
|
+
} & {
|
32
|
+
icon?: string | undefined;
|
33
|
+
})[];
|
34
|
+
};
|
35
|
+
};
|
36
|
+
};
|
37
|
+
};
|
38
|
+
} & {
|
39
|
+
creators: {
|
40
|
+
":id": {
|
41
|
+
get: {
|
42
|
+
body: unknown;
|
43
|
+
params: {
|
44
|
+
id: string;
|
45
|
+
};
|
46
|
+
query: unknown;
|
47
|
+
headers: unknown;
|
48
|
+
response: {
|
49
|
+
200: {
|
50
|
+
name: string;
|
51
|
+
id: string;
|
52
|
+
addresses: string[];
|
53
|
+
icon?: string | undefined;
|
54
|
+
};
|
55
|
+
};
|
56
|
+
};
|
57
|
+
};
|
58
|
+
};
|
59
|
+
} & {
|
60
|
+
creators: {
|
61
|
+
index: {
|
62
|
+
post: {
|
63
|
+
body: {
|
64
|
+
icon?: string | undefined;
|
65
|
+
name: string;
|
66
|
+
id: string;
|
67
|
+
addresses: string[];
|
68
|
+
};
|
69
|
+
params: {};
|
70
|
+
query: unknown;
|
71
|
+
headers: {
|
72
|
+
authorization: string;
|
73
|
+
};
|
74
|
+
response: {
|
75
|
+
200: {
|
76
|
+
name: string;
|
77
|
+
id: string;
|
78
|
+
icon: string | null;
|
79
|
+
};
|
80
|
+
};
|
81
|
+
};
|
82
|
+
};
|
83
|
+
};
|
84
|
+
} & {
|
85
|
+
creators: {
|
86
|
+
":id": {
|
87
|
+
patch: {
|
88
|
+
body: {
|
89
|
+
icon?: string | undefined;
|
90
|
+
name: string;
|
91
|
+
addresses: string[];
|
92
|
+
};
|
93
|
+
params: {
|
94
|
+
id: string;
|
95
|
+
};
|
96
|
+
query: unknown;
|
97
|
+
headers: {
|
98
|
+
authorization: string;
|
99
|
+
};
|
100
|
+
response: {
|
101
|
+
200: {
|
102
|
+
name: string;
|
103
|
+
id: string;
|
104
|
+
icon: string | null;
|
105
|
+
};
|
106
|
+
};
|
107
|
+
};
|
108
|
+
};
|
109
|
+
};
|
110
|
+
}, {
|
111
|
+
derive: {};
|
112
|
+
resolve: {};
|
113
|
+
schema: {};
|
114
|
+
}, {
|
115
|
+
derive: {};
|
116
|
+
resolve: {};
|
117
|
+
schema: {};
|
118
|
+
}>;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { NotFoundError } from "../../../errors";
|
2
|
+
import { AuthorizationHeadersDto, BackOfficeGuard } from "../../../guards/BackOffice.guard";
|
3
|
+
import { Elysia } from "elysia";
|
4
|
+
import { CreatorDto, GetManyCreatorQuery, UpdateCreatorDto } from "./creator.model";
|
5
|
+
import { CreatorService } from "./creator.service";
|
6
|
+
// ─── Creators Controller ────────────────────────────────────────────────────────
|
7
|
+
export const CreatorController = new Elysia({ prefix: "/creators", detail: { tags: ["Creator"] } })
|
8
|
+
// ─── Get Many Creators ──────────────────────────────────────────────────
|
9
|
+
.get("/", async ({ query }) => (await CreatorService.findMany(query)).map(CreatorService.format), {
|
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 ───────────────────────────────────────────────────
|
20
|
+
.post("/", async ({ body }) => await CreatorService.create(body), {
|
21
|
+
headers: AuthorizationHeadersDto,
|
22
|
+
body: CreatorDto,
|
23
|
+
beforeHandle: BackOfficeGuard,
|
24
|
+
})
|
25
|
+
// ─── Update Creator's Addresses ──────────────────────────────────────────────
|
26
|
+
.patch("/:id", async ({ params: { id }, body }) => CreatorService.update(id, body), {
|
27
|
+
headers: AuthorizationHeadersDto,
|
28
|
+
body: UpdateCreatorDto,
|
29
|
+
beforeHandle: BackOfficeGuard,
|
30
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import type { Resource } from "../prisma";
|
2
|
+
/**
|
3
|
+
* Campaign Creator (Client)
|
4
|
+
* @description A group of user that represent a campaign creator
|
5
|
+
* @see {@link Resource}
|
6
|
+
*/
|
7
|
+
export type Creator = Resource<"Creator", "icon", {
|
8
|
+
icon?: string;
|
9
|
+
addresses: string[];
|
10
|
+
}>;
|
11
|
+
export declare const CreatorDto: import("@sinclair/typebox").TObject<{
|
12
|
+
addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
13
|
+
icon: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
14
|
+
id: import("@sinclair/typebox").TString;
|
15
|
+
name: import("@sinclair/typebox").TString;
|
16
|
+
}>;
|
17
|
+
export declare const GetManyCreatorQuery: import("@sinclair/typebox").TObject<{
|
18
|
+
address: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
19
|
+
page: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
20
|
+
items: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
21
|
+
}>;
|
22
|
+
export declare const UpdateCreatorDto: import("@sinclair/typebox").TObject<{
|
23
|
+
addresses: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
|
24
|
+
icon: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
25
|
+
name: import("@sinclair/typebox").TString;
|
26
|
+
}>;
|
27
|
+
export type CreatorModel = typeof CreatorDto.static;
|
28
|
+
export type GetManyCreatorModel = typeof GetManyCreatorQuery.static;
|
29
|
+
export type UpdateCreatorDto = typeof UpdateCreatorDto.static;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { t } from "elysia";
|
2
|
+
// ─── Dtos ────────────────────────────────────────────────────────────────────
|
3
|
+
export const CreatorDto = t.Object({
|
4
|
+
addresses: t.Array(t.String()),
|
5
|
+
icon: t.Optional(t.String()),
|
6
|
+
id: t.String(),
|
7
|
+
name: t.String(),
|
8
|
+
});
|
9
|
+
export const GetManyCreatorQuery = t.Object({
|
10
|
+
address: t.Optional(t.String()),
|
11
|
+
page: t.Optional(t.Number()),
|
12
|
+
items: t.Optional(t.Number()),
|
13
|
+
});
|
14
|
+
export const UpdateCreatorDto = t.Object({
|
15
|
+
addresses: t.Array(t.String()),
|
16
|
+
icon: t.Optional(t.String()),
|
17
|
+
name: t.String(),
|
18
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import type { Creator, GetManyCreatorModel, UpdateCreatorDto } from "./creator.model";
|
2
|
+
export declare abstract class CreatorRepository {
|
3
|
+
static findUnique(id: Creator["model"]["id"]): Promise<({
|
4
|
+
Users: {
|
5
|
+
tags: string[];
|
6
|
+
address: string;
|
7
|
+
creatorId: string | null;
|
8
|
+
}[];
|
9
|
+
} & {
|
10
|
+
name: string;
|
11
|
+
id: string;
|
12
|
+
icon: string | null;
|
13
|
+
}) | null>;
|
14
|
+
static findUniqueFromAddress(address: string): Promise<{
|
15
|
+
name: string;
|
16
|
+
id: string;
|
17
|
+
icon: string | null;
|
18
|
+
} | null>;
|
19
|
+
static findMany(query: GetManyCreatorModel): Promise<({
|
20
|
+
Users: {
|
21
|
+
tags: string[];
|
22
|
+
address: string;
|
23
|
+
creatorId: string | null;
|
24
|
+
}[];
|
25
|
+
} & {
|
26
|
+
name: string;
|
27
|
+
id: string;
|
28
|
+
icon: string | null;
|
29
|
+
})[]>;
|
30
|
+
static create({ addresses, ...creator }: Creator["model"]): Promise<{
|
31
|
+
name: string;
|
32
|
+
id: string;
|
33
|
+
icon: string | null;
|
34
|
+
}>;
|
35
|
+
static update(id: Creator["model"]["id"], { addresses, ...creator }: UpdateCreatorDto): Promise<{
|
36
|
+
name: string;
|
37
|
+
id: string;
|
38
|
+
icon: string | null;
|
39
|
+
}>;
|
40
|
+
}
|
@@ -0,0 +1,63 @@
|
|
1
|
+
import { apiDbClient } from "../../../utils/prisma";
|
2
|
+
// ─── Users Repository ────────────────────────────────────────────────────────
|
3
|
+
export class CreatorRepository {
|
4
|
+
static async findUnique(id) {
|
5
|
+
return await apiDbClient.creator.findUnique({ where: { id }, include: { Users: true } });
|
6
|
+
}
|
7
|
+
static async findUniqueFromAddress(address) {
|
8
|
+
const creator = await apiDbClient.user.findUnique({ where: { address: address }, select: { Creator: true } });
|
9
|
+
return creator?.Creator ?? null;
|
10
|
+
}
|
11
|
+
static async findMany(query) {
|
12
|
+
const { page: _page, items: _items, ...filters } = query;
|
13
|
+
const page = _page ? _page : 0;
|
14
|
+
const items = _items ? _items : 20;
|
15
|
+
return await apiDbClient.creator.findMany({
|
16
|
+
take: items,
|
17
|
+
skip: page * items,
|
18
|
+
include: { Users: true },
|
19
|
+
where: {
|
20
|
+
Users: filters.address
|
21
|
+
? {
|
22
|
+
some: {
|
23
|
+
address: {
|
24
|
+
equals: filters.address,
|
25
|
+
},
|
26
|
+
},
|
27
|
+
}
|
28
|
+
: undefined,
|
29
|
+
},
|
30
|
+
});
|
31
|
+
}
|
32
|
+
static async create({ addresses, ...creator }) {
|
33
|
+
return await apiDbClient.creator.create({
|
34
|
+
data: {
|
35
|
+
...creator,
|
36
|
+
Users: {
|
37
|
+
connectOrCreate: addresses.map(address => ({
|
38
|
+
create: {
|
39
|
+
address,
|
40
|
+
},
|
41
|
+
where: { address },
|
42
|
+
})),
|
43
|
+
},
|
44
|
+
},
|
45
|
+
});
|
46
|
+
}
|
47
|
+
static async update(id, { addresses, ...creator }) {
|
48
|
+
return await apiDbClient.creator.update({
|
49
|
+
where: { id },
|
50
|
+
data: {
|
51
|
+
...creator,
|
52
|
+
Users: {
|
53
|
+
connectOrCreate: addresses.map(address => ({
|
54
|
+
create: {
|
55
|
+
address,
|
56
|
+
},
|
57
|
+
where: { address },
|
58
|
+
})),
|
59
|
+
},
|
60
|
+
},
|
61
|
+
});
|
62
|
+
}
|
63
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
import type { Creator, GetManyCreatorModel, UpdateCreatorDto } from "./creator.model";
|
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
|
+
/**
|
10
|
+
* Finds a creator from its id (i.e. "uniswap")
|
11
|
+
* @param id
|
12
|
+
* @returns creator
|
13
|
+
*/
|
14
|
+
static findUnique(id: Creator["model"]["id"]): Promise<({
|
15
|
+
Users: {
|
16
|
+
tags: string[];
|
17
|
+
address: string;
|
18
|
+
creatorId: string | null;
|
19
|
+
}[];
|
20
|
+
} & {
|
21
|
+
name: string;
|
22
|
+
id: string;
|
23
|
+
icon: string | null;
|
24
|
+
}) | null>;
|
25
|
+
/**
|
26
|
+
* Finds many creator
|
27
|
+
* @param id
|
28
|
+
* @returns creator
|
29
|
+
*/
|
30
|
+
static findMany(query: GetManyCreatorModel): Promise<({
|
31
|
+
Users: {
|
32
|
+
tags: string[];
|
33
|
+
address: string;
|
34
|
+
creatorId: string | null;
|
35
|
+
}[];
|
36
|
+
} & {
|
37
|
+
name: string;
|
38
|
+
id: string;
|
39
|
+
icon: string | null;
|
40
|
+
})[]>;
|
41
|
+
/**
|
42
|
+
* Creates a creator
|
43
|
+
* @param creator {addresses, id, name}
|
44
|
+
*/
|
45
|
+
static create(creator: Creator["model"]): Promise<{
|
46
|
+
name: string;
|
47
|
+
id: string;
|
48
|
+
icon: string | null;
|
49
|
+
}>;
|
50
|
+
/**
|
51
|
+
* Updates data on a creator
|
52
|
+
* @notice will override the entire address array
|
53
|
+
* @param id of creator
|
54
|
+
* @param creator data for each field
|
55
|
+
*/
|
56
|
+
static update(id: Creator["model"]["id"], creator: UpdateCreatorDto): Promise<{
|
57
|
+
name: string;
|
58
|
+
id: string;
|
59
|
+
icon: string | null;
|
60
|
+
}>;
|
61
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import { CreatorRepository } from "./creator.repository";
|
2
|
+
// ─── Creators Services ──────────────────────────────────────────────────────────
|
3
|
+
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
|
+
/**
|
13
|
+
* Finds a creator from its id (i.e. "uniswap")
|
14
|
+
* @param id
|
15
|
+
* @returns creator
|
16
|
+
*/
|
17
|
+
static async findUnique(id) {
|
18
|
+
return await CreatorRepository.findUnique(id);
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* Finds many creator
|
22
|
+
* @param id
|
23
|
+
* @returns creator
|
24
|
+
*/
|
25
|
+
static async findMany(query) {
|
26
|
+
return await CreatorRepository.findMany(query);
|
27
|
+
}
|
28
|
+
/**
|
29
|
+
* Creates a creator
|
30
|
+
* @param creator {addresses, id, name}
|
31
|
+
*/
|
32
|
+
static async create(creator) {
|
33
|
+
return await CreatorRepository.create(creator);
|
34
|
+
}
|
35
|
+
/**
|
36
|
+
* Updates data on a creator
|
37
|
+
* @notice will override the entire address array
|
38
|
+
* @param id of creator
|
39
|
+
* @param creator data for each field
|
40
|
+
*/
|
41
|
+
static async update(id, creator) {
|
42
|
+
return await CreatorRepository.update(id, creator);
|
43
|
+
}
|
44
|
+
}
|
@@ -72,8 +72,7 @@ export declare const DynamicDataController: Elysia<"/dynamic-data", false, {
|
|
72
72
|
authorization: string;
|
73
73
|
};
|
74
74
|
response: {
|
75
|
-
|
76
|
-
200: any;
|
75
|
+
200: any[];
|
77
76
|
};
|
78
77
|
};
|
79
78
|
};
|
@@ -96,6 +95,7 @@ export declare const DynamicDataController: Elysia<"/dynamic-data", false, {
|
|
96
95
|
mainParameter?: string | undefined;
|
97
96
|
campaignId?: string | undefined;
|
98
97
|
opportunityId?: string | undefined;
|
98
|
+
creatorId?: string | undefined;
|
99
99
|
test?: boolean | undefined;
|
100
100
|
creatorTag?: string | undefined;
|
101
101
|
tokenSymbol?: string | undefined;
|
@@ -104,8 +104,7 @@ export declare const DynamicDataController: Elysia<"/dynamic-data", false, {
|
|
104
104
|
authorization: string;
|
105
105
|
};
|
106
106
|
response: {
|
107
|
-
|
108
|
-
200: any;
|
107
|
+
200: any[];
|
109
108
|
};
|
110
109
|
};
|
111
110
|
};
|
@@ -25,7 +25,7 @@ export const DynamicDataController = new Elysia({
|
|
25
25
|
BackOfficeGuard({ headers });
|
26
26
|
},
|
27
27
|
})
|
28
|
-
.get("/from-existing", async ({ query }) => await DynamicDataService.
|
28
|
+
.get("/from-existing", async ({ query }) => await DynamicDataService.queryDynamicDataFromManyCampaignId(query), {
|
29
29
|
query: GetCampaignQueryDto,
|
30
30
|
headers: AuthorizationHeadersDto,
|
31
31
|
beforeHandle: ({ headers }) => {
|
@@ -97,6 +97,7 @@ export declare const FilledCampaignDto: import("@sinclair/typebox").TObject<{
|
|
97
97
|
startTimestamp: import("@sinclair/typebox").TString;
|
98
98
|
endTimestamp: import("@sinclair/typebox").TString;
|
99
99
|
campaignParameters: import("@sinclair/typebox").TObject<{}>;
|
100
|
+
mainParameter: import("@sinclair/typebox").TString;
|
100
101
|
}>;
|
101
102
|
export type DynamicDataSourceModel = typeof DynamicDataSourceIdentifier.static;
|
102
103
|
export type SimplifiedCampaignDtoModel = typeof SimplifiedCampaignDto.static;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { CampaignType } from "../../../../database/api/.generated";
|
2
2
|
import { Campaign, type ChainId } from "@sdk";
|
3
3
|
import { type GetCampaignQueryModel } from "../campaign";
|
4
|
-
import type { SimplifiedCampaignDtoModel } from "./dynamicData.model";
|
4
|
+
import type { FilledCampaignDtoModel, SimplifiedCampaignDtoModel } from "./dynamicData.model";
|
5
5
|
type output = {
|
6
6
|
tvl: number;
|
7
7
|
totalSupply: number;
|
@@ -14,8 +14,11 @@ export declare class DynamicDataService {
|
|
14
14
|
#private;
|
15
15
|
/** Fetches a single price */
|
16
16
|
static queryERC20DynamicData(chainId: ChainId, tokenAddress: string, decimals?: number): Promise<output>;
|
17
|
-
static
|
18
|
-
static
|
17
|
+
static generateDummyData(campaign: SimplifiedCampaignDtoModel): FilledCampaignDtoModel;
|
18
|
+
static generateMainParameter(campaign: SimplifiedCampaignDtoModel): string;
|
19
|
+
static queryDynamicData(campaign: SimplifiedCampaignDtoModel): Promise<any[]>;
|
20
|
+
static queryDynamicDataFromCampaignId(query: GetCampaignQueryModel): Promise<any[]>;
|
21
|
+
static queryDynamicDataFromManyCampaignId(query: GetCampaignQueryModel): Promise<any[]>;
|
19
22
|
/**
|
20
23
|
* Returns the campaign type index from the CampaignType enum
|
21
24
|
* @param type CampaignType as db-related enum for v4
|
@@ -3,8 +3,10 @@ import { executeSimple } from "../../../utils/execute";
|
|
3
3
|
import { log } from "../../../utils/logger";
|
4
4
|
import { CampaignType } from "../../../../database/api/.generated";
|
5
5
|
import { Campaign, NETWORK_LABELS } from "@sdk";
|
6
|
+
import { utils } from "ethers";
|
6
7
|
import { CampaignService, campaignTypeToEnumMap } from "../campaign";
|
7
8
|
import { CampaignRepository } from "../campaign/campaign.repository";
|
9
|
+
import { OpportunityService } from "../opportunity";
|
8
10
|
export class DynamicDataService {
|
9
11
|
// ─── DynamicDatas ──────────────────────────────────────────────────────────
|
10
12
|
/** Fetches a single price */
|
@@ -50,7 +52,7 @@ export class DynamicDataService {
|
|
50
52
|
type: result[0]?.type ?? "defaultType",
|
51
53
|
};
|
52
54
|
}
|
53
|
-
static
|
55
|
+
static generateDummyData(campaign) {
|
54
56
|
const campaignParameters = {
|
55
57
|
type: campaign.type,
|
56
58
|
computeChainId: campaign.computeChainId,
|
@@ -64,21 +66,46 @@ export class DynamicDataService {
|
|
64
66
|
: (Math.floor(Date.now() / 1000) + 30 * 24 * 60 * 60).toString(), // 30 days from now
|
65
67
|
creatorAddress: campaign.creatorAddress ? campaign.creatorAddress : "0xdefaultcreatoraddress",
|
66
68
|
campaignParameters: campaign.params,
|
67
|
-
campaignId: "0xdefaultid",
|
69
|
+
campaignId: campaign.id ? campaign.id : "0xdefaultid",
|
68
70
|
opportunityIdentifier: "0xdefaultopportunityid",
|
69
|
-
id: "0xdefaultid",
|
71
|
+
id: campaign.id ? campaign.id : "0xdefaultid",
|
70
72
|
distributionChainId: campaign.distributionChainId ? campaign.distributionChainId : 1,
|
71
73
|
rewardTokenId: campaign.rewardTokenId ? campaign.rewardTokenId : "0xdefaultrewardtokenid",
|
72
74
|
opportunityId: campaign.opportunityId ? campaign.opportunityId : "0xdefaultopportunityid",
|
73
75
|
identifier: campaign.identifier ? campaign.identifier : "defaultidentifier",
|
76
|
+
mainParameter: DynamicDataService.generateMainParameter(campaign),
|
74
77
|
};
|
75
|
-
return
|
78
|
+
return campaignParameters;
|
79
|
+
}
|
80
|
+
static generateMainParameter(campaign) {
|
81
|
+
let targetToken;
|
82
|
+
let parsedParams;
|
83
|
+
if (campaign.type === "CLAMM") {
|
84
|
+
parsedParams = campaign.params;
|
85
|
+
targetToken = parsedParams.poolAddress;
|
86
|
+
}
|
87
|
+
else {
|
88
|
+
parsedParams = campaign.params;
|
89
|
+
targetToken = parsedParams.targetToken;
|
90
|
+
}
|
91
|
+
return utils
|
92
|
+
.keccak256(utils.defaultAbiCoder.encode(["string", "address[]"], [targetToken, parsedParams.whitelist.sort()]))
|
93
|
+
.slice(0, 42);
|
94
|
+
}
|
95
|
+
static async queryDynamicData(campaign) {
|
96
|
+
const campaignParameters = DynamicDataService.generateDummyData(campaign);
|
97
|
+
return await DynamicDataService.#getMultipleDynamicData([campaignParameters]);
|
76
98
|
}
|
77
99
|
static async queryDynamicDataFromCampaignId(query) {
|
78
100
|
const campaigns = await CampaignRepository.findMany(query);
|
79
101
|
const campaign = campaigns[0];
|
80
102
|
return DynamicDataService.queryDynamicData(CampaignService.format(campaign));
|
81
103
|
}
|
104
|
+
static async queryDynamicDataFromManyCampaignId(query) {
|
105
|
+
const campaigns = await CampaignRepository.findMany(query);
|
106
|
+
const formattedCampaigns = campaigns.map(campaign => DynamicDataService.generateDummyData(CampaignService.format(campaign)));
|
107
|
+
return DynamicDataService.#getMultipleDynamicData(formattedCampaigns);
|
108
|
+
}
|
82
109
|
/**
|
83
110
|
* Returns the campaign type index from the CampaignType enum
|
84
111
|
* @param type CampaignType as db-related enum for v4
|
@@ -87,15 +114,29 @@ export class DynamicDataService {
|
|
87
114
|
static getV3FromType(type) {
|
88
115
|
return Object.entries(campaignTypeToEnumMap).find(([v4]) => v4 === type)?.[1];
|
89
116
|
}
|
90
|
-
/**
|
91
|
-
* build/fetch metadata of a campaign's opportunity
|
92
|
-
* @param campaign
|
93
|
-
* @returns {OpportunityMetadata}
|
94
|
-
*/
|
95
117
|
static async #getDynamicData(campaign) {
|
96
118
|
// const campaignType = DynamicDataService.getV3FromType(campaign.type);
|
97
119
|
if (campaign.type !== CampaignType.INVALID) {
|
98
120
|
return await CampaignService.fetchDynamicData(campaign.computeChainId, campaign.type, [campaign]);
|
99
121
|
}
|
100
122
|
}
|
123
|
+
static async #getMultipleDynamicData(campaigns) {
|
124
|
+
const result = [];
|
125
|
+
// const campaignType = DynamicDataService.getV3FromType(campaign.type);
|
126
|
+
const campaign = campaigns[0];
|
127
|
+
const filteredCampaigns = campaigns.filter(c => c.type === campaign.type);
|
128
|
+
if (campaign.type !== CampaignType.INVALID) {
|
129
|
+
const resultDynamicData = await CampaignService.fetchDynamicData(campaign.computeChainId, campaign.type, filteredCampaigns);
|
130
|
+
for (const campaign of campaigns) {
|
131
|
+
const resultMetaData = await OpportunityService.fakeCreateFromCampaign({
|
132
|
+
...campaign,
|
133
|
+
type: campaignTypeToEnumMap[campaign.type],
|
134
|
+
params: JSON.stringify(campaign.campaignParameters),
|
135
|
+
creator: campaign.creatorAddress,
|
136
|
+
});
|
137
|
+
result.push({ ...resultDynamicData.find(data => data.campaignId === campaign.campaignId), ...resultMetaData });
|
138
|
+
}
|
139
|
+
}
|
140
|
+
return result;
|
141
|
+
}
|
101
142
|
}
|