@merkl/api 0.20.113 → 0.20.115
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 -5
- package/dist/src/engine/deprecated/dynamicData/factory.js +1 -0
- package/dist/src/engine/deprecated/dynamicData/implementations/EventBased.js +1 -1
- package/dist/src/engine/deprecated/dynamicData/implementations/default.d.ts +3 -3
- package/dist/src/engine/deprecated/erc20SubTypeProcessors/subtypesRound1.js +3 -8
- package/dist/src/engine/implementations/Ajna/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Ambient/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Badger/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Clamm/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Compound/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/CompoundV3/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Default/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Dolomite/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/EigenLayer/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/EigenLayer/tvl.d.ts +7 -0
- package/dist/src/engine/implementations/EigenLayer/tvl.js +60 -0
- package/dist/src/engine/implementations/Encompassing/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Erc20/metadata.d.ts +1 -12
- package/dist/src/engine/implementations/Erc20/metadata.js +3 -3
- package/dist/src/engine/implementations/Erc20/subTypes/factories.js +6 -0
- package/dist/src/engine/implementations/Erc20/subTypes/implementations/gearbox/tvl.js +1 -1
- package/dist/src/engine/implementations/Erc20/subTypes/implementations/superlend/metadata.d.ts +17 -0
- package/dist/src/engine/implementations/Erc20/subTypes/implementations/superlend/metadata.js +29 -0
- package/dist/src/engine/implementations/Erc20/subTypes/implementations/superlend/tvl.d.ts +6 -0
- package/dist/src/engine/implementations/Erc20/subTypes/implementations/superlend/tvl.js +48 -0
- package/dist/src/engine/implementations/Erc20/tvl.js +1 -1
- package/dist/src/engine/implementations/Erc20Snapshot/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Erc721/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/ErcMultiToken/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Euler/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Euler/metadata.js +2 -2
- package/dist/src/engine/implementations/EventBased/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Hyperdrive/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Invalid/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Ion/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/JsonAirdrop/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Morpho/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Radiant/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Silo/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/UniswapV4/metadata.d.ts +2 -2
- package/dist/src/engine/implementations/Vest/metadata.d.ts +2 -2
- package/dist/src/engine/metadata/factory.js +1 -0
- package/dist/src/engine/tvl/factory.js +2 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/jobs/update-dynamic-data.js +2 -2
- package/dist/src/modules/v4/campaign/campaign.model.d.ts +2 -2
- package/dist/src/modules/v4/campaign/campaign.service.d.ts +4 -4
- package/dist/src/modules/v4/campaign/campaign.service.js +3 -3
- package/dist/src/modules/v4/campaign/campaign.test.controller.d.ts +1 -1
- package/dist/src/modules/v4/campaign/campaign.test.controller.js +18 -7
- package/dist/src/modules/v4/dynamicData/dynamicData.service.d.ts +3 -3
- package/dist/src/modules/v4/dynamicData/dynamicData.service.js +10 -10
- package/dist/src/modules/v4/opportunity/opportunity.converter.d.ts +2 -2
- package/dist/src/modules/v4/opportunity/opportunity.converter.js +5 -5
- package/dist/src/modules/v4/opportunity/opportunity.service.js +2 -2
- package/dist/src/modules/v4/opportunity/validate-id.pipe.js +3 -3
- package/dist/src/modules/v4/reward/reward.service.d.ts +2 -2
- package/dist/src/modules/v4/reward/reward.service.js +2 -2
- package/dist/src/modules/v4/router.d.ts +1 -1
- package/dist/src/modules/v4/token/token.service.d.ts +20 -0
- package/dist/src/modules/v4/token/token.service.js +19 -0
- package/dist/src/routes/v3/campaigns.js +3 -3
- package/dist/src/routes/v3/campaignsForMainParameter.js +2 -2
- package/dist/src/scripts/reparse-opportunities.js +2 -2
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { MetadataBuilder } from "@/engine/metadata/interface";
|
2
2
|
import type { CampaignWithParams } from "@/modules/v4/campaign";
|
3
3
|
import type { ProtocolId } from "@/modules/v4/protocol/protocol.model";
|
4
|
-
import { type Campaign as
|
4
|
+
import { type CampaignParameters, type Campaign as CampaignType, ChainId } from "@sdk";
|
5
5
|
import type { BigNumberish } from "ethers";
|
6
|
-
type campaignType =
|
6
|
+
type campaignType = CampaignType.MORPHO;
|
7
7
|
export declare class MorphoMetadata implements MetadataBuilder<campaignType> {
|
8
8
|
build(campaign: Omit<CampaignWithParams<campaignType>, "manualOverrides">): Promise<{
|
9
9
|
action: "LEND" | "BORROW";
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { CampaignWithParams } from "@/modules/v4/campaign";
|
2
2
|
import type { ProtocolId } from "@/modules/v4/protocol/protocol.model";
|
3
|
-
import { type Campaign as
|
3
|
+
import { type Campaign as CampaignType } from "@sdk";
|
4
4
|
import type { MetadataBuilder } from "../../metadata/interface";
|
5
|
-
type campaignType =
|
5
|
+
type campaignType = CampaignType.RADIANT;
|
6
6
|
export declare class RadiantMetadata implements MetadataBuilder<campaignType> {
|
7
7
|
build(campaign: Omit<CampaignWithParams<campaignType>, "manualOverrides">): Promise<{
|
8
8
|
action: "LEND" | "BORROW";
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { MetadataBuilder } from "@/engine/metadata/interface";
|
2
2
|
import type { CampaignWithParams } from "@/modules/v4/campaign";
|
3
3
|
import type { ProtocolId } from "@/modules/v4/protocol/protocol.model";
|
4
|
-
import type { Campaign as
|
5
|
-
type campaignType =
|
4
|
+
import type { Campaign as CampaignType } from "@sdk";
|
5
|
+
type campaignType = CampaignType.SILO;
|
6
6
|
export declare class SiloMetadata implements MetadataBuilder<campaignType> {
|
7
7
|
build(campaign: Omit<CampaignWithParams<campaignType>, "manualOverrides">): Promise<{
|
8
8
|
action: "LEND" | "BORROW";
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { MetadataBuilder } from "@/engine/metadata/interface";
|
2
2
|
import type { CampaignWithParams } from "@/modules/v4/campaign";
|
3
3
|
import type { ProtocolId } from "@/modules/v4/protocol/protocol.model";
|
4
|
-
import type { Campaign as
|
5
|
-
type campaignType =
|
4
|
+
import type { CampaignParameters, Campaign as CampaignType, ChainId } from "@sdk";
|
5
|
+
type campaignType = CampaignType.UNISWAP_V4;
|
6
6
|
export declare class UniswapV4Metadata implements MetadataBuilder<campaignType> {
|
7
7
|
build(campaign: Omit<CampaignWithParams<campaignType>, "manualOverrides">): Promise<{
|
8
8
|
name: string;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import type { MetadataBuilder } from "@/engine/metadata/interface";
|
2
2
|
import type { CampaignWithParams } from "@/modules/v4/campaign";
|
3
3
|
import type { ProtocolId } from "@/modules/v4/protocol/protocol.model";
|
4
|
-
import type { Campaign as
|
5
|
-
type campaignType =
|
4
|
+
import type { Campaign as CampaignType } from "@sdk";
|
5
|
+
type campaignType = CampaignType.VEST;
|
6
6
|
export declare class VestMetadata implements MetadataBuilder<campaignType> {
|
7
7
|
build(campaign: Omit<CampaignWithParams<campaignType>, "manualOverrides">): Promise<{
|
8
8
|
action: "LEND";
|
@@ -67,5 +67,6 @@ const map = {
|
|
67
67
|
[Campaign.ERC1155FIXAPR]: new ErcMultiTokenMetadata(),
|
68
68
|
[Campaign.ERC721]: new Erc721Metadata(),
|
69
69
|
[Campaign.ERC721FIXAPR]: new Erc721Metadata(),
|
70
|
+
[Campaign.MULTILOG]: new DefaultMetadata(), // TODO
|
70
71
|
};
|
71
72
|
export const metadataBuilderFactory = (campaignType) => map[campaignType];
|
@@ -2,6 +2,7 @@ import { UniswapV4TVLBuilder } from "@/engine/implementations/UniswapV4/tvl";
|
|
2
2
|
import { Campaign } from "@sdk";
|
3
3
|
import { AjnaTVLBuilder } from "../implementations/Ajna/tvl";
|
4
4
|
import { AmbiantTVLBuilder } from "../implementations/Ambient/tvl";
|
5
|
+
import { EigenLayerTVLBuilder } from "../implementations/EigenLayer/tvl";
|
5
6
|
import { Erc20TVLBuilder } from "../implementations/Erc20/tvl";
|
6
7
|
/**
|
7
8
|
* @dev TYPE SAFETY DISABLED FOR NOW AS WE DON'T HAVE ALL THE CAMPAIGNS IMPLEMENTED
|
@@ -11,6 +12,7 @@ import { Erc20TVLBuilder } from "../implementations/Erc20/tvl";
|
|
11
12
|
*/
|
12
13
|
const map = {
|
13
14
|
[Campaign.AJNA]: new AjnaTVLBuilder(),
|
15
|
+
[Campaign.EIGENLAYER]: new EigenLayerTVLBuilder(),
|
14
16
|
[Campaign.AMBIENTPROCESSOR]: new AmbiantTVLBuilder(),
|
15
17
|
[Campaign.UNISWAP_V4]: new UniswapV4TVLBuilder(),
|
16
18
|
[Campaign.ERC20]: new Erc20TVLBuilder(),
|
package/dist/src/index.d.ts
CHANGED
@@ -2133,8 +2133,8 @@ declare const app: Elysia<"", false, {
|
|
2133
2133
|
body: unknown;
|
2134
2134
|
params: {};
|
2135
2135
|
query: {
|
2136
|
+
distributionChain?: number | undefined;
|
2136
2137
|
campaignId: string;
|
2137
|
-
distributionChain: number;
|
2138
2138
|
};
|
2139
2139
|
headers: {
|
2140
2140
|
authorization: string;
|
@@ -3,7 +3,7 @@ import { DynamicDataService } from "@/modules/v4/dynamicData/dynamicData.service
|
|
3
3
|
import { OpportunityService } from "@/modules/v4/opportunity";
|
4
4
|
import { OpportunityConvertorService } from "@/modules/v4/opportunity/opportunity.converter";
|
5
5
|
import { logger } from "@/utils/logger";
|
6
|
-
import { Campaign as
|
6
|
+
import { Campaign as CampaignType } from "@sdk";
|
7
7
|
import moment from "moment";
|
8
8
|
// ─── Required Env Variables ──────────────────────────────────────────────────
|
9
9
|
const chainId = Number(process.env.CHAIN_ID);
|
@@ -52,7 +52,7 @@ const main = async () => {
|
|
52
52
|
// 4. Update the status of the opportunities associated to live campaigns
|
53
53
|
await OpportunityService.updateMany(liveOpportunityIds, { status: "LIVE" });
|
54
54
|
// 5. Update records for all live campaigns
|
55
|
-
const liveCampaigns = (await CampaignService.findMany({ chainId, status: "LIVE", test: true, withOpportunity: true, items: 10_000 })).map(campaign => OpportunityConvertorService.convertV4CampaignToV3(
|
55
|
+
const liveCampaigns = (await CampaignService.findMany({ chainId, status: "LIVE", test: true, withOpportunity: true, items: 10_000 })).map(campaign => OpportunityConvertorService.convertV4CampaignToV3(CampaignType[campaign.type], campaign, campaign.Opportunity.identifier));
|
56
56
|
const promises = [];
|
57
57
|
for (const type of new Set(liveCampaigns.map(c => c.campaignType))) {
|
58
58
|
promises.push(DynamicDataService.update(chainId, type, liveCampaigns.filter(c => c.campaignType === type)));
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { Resource } from "@/modules/v4/prisma";
|
2
2
|
import { type Token } from "@/modules/v4/token/token.model";
|
3
|
-
import type { Campaign as
|
3
|
+
import type { CampaignParameters, Campaign as CampaignType } from "@sdk";
|
4
4
|
import { type Chain } from "../chain/chain.model";
|
5
5
|
import { type Status as StatusModel } from "../status/status.model";
|
6
6
|
/**
|
@@ -22,7 +22,7 @@ export type Campaign = Resource<"Campaign", "opportunityId" | "rewardTokenId", {
|
|
22
22
|
startTimestamp: number;
|
23
23
|
createdAt: string;
|
24
24
|
}>;
|
25
|
-
export type CampaignWithParams<C extends
|
25
|
+
export type CampaignWithParams<C extends CampaignType = CampaignType> = Campaign["model"] & {
|
26
26
|
params: CampaignParameters<C>["campaignParameters"];
|
27
27
|
};
|
28
28
|
export declare const CampaignUniqueDto: import("@sinclair/typebox").TObject<{
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { CampaignConfigMinimalModel, CampaignUnique, CampaignWithParams, CreateCampaignModel, GetCampaignQueryModel, UpdateCampaignCreatorModel, UpdateCampaignModel, UpdateMetaDataCampaignModel } from "@/modules/v4/campaign";
|
2
2
|
import type { CampaignManualOverride } from "@db/api";
|
3
|
-
import { Campaign as
|
3
|
+
import { type CampaignParameters, Campaign as CampaignType, type ChainId } from "@sdk";
|
4
4
|
import type { GetCampaignComputedValueModel } from "../computedValue/computedValue.model";
|
5
5
|
import { CampaignRepository } from "./campaign.repository";
|
6
6
|
export declare abstract class CampaignService {
|
@@ -708,7 +708,7 @@ export declare abstract class CampaignService {
|
|
708
708
|
* @param type index of Campaign enum from sdk
|
709
709
|
* @returns a string
|
710
710
|
*/
|
711
|
-
static getTypeFromV3(type:
|
711
|
+
static getTypeFromV3(type: CampaignType): string;
|
712
712
|
/**
|
713
713
|
* Split a campaigns array into three array for each status
|
714
714
|
* @param campaigns
|
@@ -805,7 +805,7 @@ export declare abstract class CampaignService {
|
|
805
805
|
/**
|
806
806
|
* @deprecated Used only in tentative position fetcher
|
807
807
|
*/
|
808
|
-
static formatAsCampaignParameters<C extends
|
808
|
+
static formatAsCampaignParameters<C extends CampaignType>(campaign: CampaignWithParams): CampaignParameters<C>;
|
809
809
|
/**
|
810
810
|
* Shortcut to get daily amount from total
|
811
811
|
* @param start timestamp
|
@@ -814,7 +814,7 @@ export declare abstract class CampaignService {
|
|
814
814
|
* @returns daily token amount
|
815
815
|
*/
|
816
816
|
static getDailyAmount<T extends bigint | number>(start: T, end: T, amount: bigint): bigint;
|
817
|
-
static createFakeCampaign<C extends
|
817
|
+
static createFakeCampaign<C extends CampaignType>(body: CampaignConfigMinimalModel): CampaignParameters<C>;
|
818
818
|
static createFakeCampaignEngine(body: CampaignConfigMinimalModel): {
|
819
819
|
computeChainId: any;
|
820
820
|
chainId: any;
|
@@ -4,7 +4,7 @@ import { StatusService } from "@/modules/v4/status/status.service";
|
|
4
4
|
import { TokenService } from "@/modules/v4/token/token.service";
|
5
5
|
import { CannotParseOpportunity, InvalidParameter } from "@/utils/error";
|
6
6
|
import { log } from "@/utils/logger";
|
7
|
-
import { Campaign as
|
7
|
+
import { Campaign as CampaignType, NETWORK_LABELS, } from "@sdk";
|
8
8
|
import { utils } from "ethers";
|
9
9
|
import moment from "moment";
|
10
10
|
import { ChainService } from "../chain/chain.service";
|
@@ -276,7 +276,7 @@ export class CampaignService {
|
|
276
276
|
* @returns a string
|
277
277
|
*/
|
278
278
|
static getTypeFromV3(type) {
|
279
|
-
return
|
279
|
+
return CampaignType[type];
|
280
280
|
}
|
281
281
|
/**
|
282
282
|
* Split a campaigns array into three array for each status
|
@@ -348,7 +348,7 @@ export class CampaignService {
|
|
348
348
|
computeChainId: body.computeChainId,
|
349
349
|
campaignParameters: body.params,
|
350
350
|
campaignSubType: body.subType ?? 0,
|
351
|
-
campaignType:
|
351
|
+
campaignType: CampaignType[body.type],
|
352
352
|
chainId: body.distributionChainId ?? 0,
|
353
353
|
creator: body.creatorAddress ?? "creator.address",
|
354
354
|
index: 0, // DEPRECATED
|
@@ -204,8 +204,8 @@ export declare const CampaignTestController: Elysia<"/campaigns", false, {
|
|
204
204
|
body: unknown;
|
205
205
|
params: {};
|
206
206
|
query: {
|
207
|
+
distributionChain?: number | undefined;
|
207
208
|
campaignId: string;
|
208
|
-
distributionChain: number;
|
209
209
|
};
|
210
210
|
headers: {
|
211
211
|
authorization: string;
|
@@ -3,12 +3,12 @@ import { InvalidParameter } from "@/errors/InvalidParameter.error";
|
|
3
3
|
import { BackOfficeGuard } from "@/guards/BackOffice.guard";
|
4
4
|
import { AuthorizationHeadersDto } from "@/guards/Engine.guard";
|
5
5
|
import { throwOnUnsupportedChainId } from "@/utils/throw";
|
6
|
-
import { Campaign as
|
7
|
-
import Elysia from "elysia";
|
6
|
+
import { Campaign as CampaignType } from "@sdk";
|
7
|
+
import Elysia, { t } from "elysia";
|
8
8
|
import { DynamicDataSourceIdentifier } from "../dynamicData/dynamicData.model";
|
9
9
|
import { DynamicDataService } from "../dynamicData/dynamicData.service";
|
10
10
|
import { OpportunityConvertorService } from "../opportunity/opportunity.converter";
|
11
|
-
import { CampaignConfigMinimal,
|
11
|
+
import { CampaignConfigMinimal, CampaignsDto } from "./campaign.model";
|
12
12
|
import { CampaignService } from "./campaign.service";
|
13
13
|
// ─── Routes for dev and test only ──────────────────────────────────────────────
|
14
14
|
export const CampaignTestController = new Elysia({
|
@@ -25,7 +25,7 @@ export const CampaignTestController = new Elysia({
|
|
25
25
|
if (!id)
|
26
26
|
throw new NotFoundError();
|
27
27
|
const campaign = await CampaignService.findUniqueOrThrow(id, true);
|
28
|
-
const campaignV3 = OpportunityConvertorService.convertV4CampaignToV3(
|
28
|
+
const campaignV3 = OpportunityConvertorService.convertV4CampaignToV3(CampaignType[campaign.type], CampaignService.format(campaign), campaign.Opportunity.identifier);
|
29
29
|
return await DynamicDataService.update(campaignV3.computeChainId, campaignV3.campaignType, [campaignV3], true);
|
30
30
|
})
|
31
31
|
// ─── Test TVL computation given a campaignId ───────────────────────
|
@@ -36,7 +36,7 @@ export const CampaignTestController = new Elysia({
|
|
36
36
|
test: true,
|
37
37
|
withOpportunity: true,
|
38
38
|
items: 10_000,
|
39
|
-
})).map(campaign => OpportunityConvertorService.convertV4CampaignToV3(
|
39
|
+
})).map(campaign => OpportunityConvertorService.convertV4CampaignToV3(CampaignType[campaign.type], campaign, campaign.Opportunity.identifier));
|
40
40
|
if (!campaigns.length)
|
41
41
|
throw new NotFoundError("Opportunity not found");
|
42
42
|
return await DynamicDataService.update(campaigns[0]?.computeChainId, campaigns[0].campaignType, campaigns, true);
|
@@ -50,7 +50,7 @@ export const CampaignTestController = new Elysia({
|
|
50
50
|
if (!id)
|
51
51
|
throw new NotFoundError();
|
52
52
|
const campaign = await CampaignService.findUniqueOrThrow(id, true);
|
53
|
-
const campaignV3 = OpportunityConvertorService.convertV4CampaignToV3(
|
53
|
+
const campaignV3 = OpportunityConvertorService.convertV4CampaignToV3(CampaignType[campaign.type], CampaignService.format(campaign), campaign.Opportunity.identifier);
|
54
54
|
listCampaigns.push(campaignV3);
|
55
55
|
}
|
56
56
|
if (!type)
|
@@ -84,6 +84,14 @@ export const CampaignTestController = new Elysia({
|
|
84
84
|
// ─── Test Opportunity creation through a campaign Id and a chain ───────────────────────
|
85
85
|
// @dev Starts from the engine db to debug opportunity creation failing and preventing the api db to be filled
|
86
86
|
.get("/metadata", async ({ query }) => {
|
87
|
+
if (!query.distributionChain) {
|
88
|
+
try {
|
89
|
+
query.distributionChain = (await CampaignService.findMany({ campaignId: query.campaignId, test: true }))?.[0]?.distributionChainId;
|
90
|
+
}
|
91
|
+
catch {
|
92
|
+
throw new NotFoundError("Campaign not found");
|
93
|
+
}
|
94
|
+
}
|
87
95
|
const engineCampaigns = await CampaignService.findEngineCampaigns([
|
88
96
|
{
|
89
97
|
distributionChain: query.distributionChain,
|
@@ -94,5 +102,8 @@ export const CampaignTestController = new Elysia({
|
|
94
102
|
throw new NotFoundError("Campaign not found in engine db");
|
95
103
|
return await CampaignService.create(engineCampaigns[0], true);
|
96
104
|
}, {
|
97
|
-
query:
|
105
|
+
query: t.Object({
|
106
|
+
distributionChain: t.Optional(t.Numeric()),
|
107
|
+
campaignId: t.String(),
|
108
|
+
}),
|
98
109
|
}));
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import { Campaign as
|
1
|
+
import { type CampaignParameters, Campaign as CampaignType, type ChainId, type MerklChainId } from "@sdk";
|
2
2
|
export declare class DynamicDataService {
|
3
3
|
/**
|
4
4
|
* @notice Updates all records for opportunities associated to the given campaigns
|
5
5
|
*
|
6
6
|
* @dev The list must ONLY contain campaigns of the same type and the same computeChainId
|
7
7
|
*/
|
8
|
-
static update(chainId: ChainId, type:
|
8
|
+
static update(chainId: ChainId, type: CampaignType, campaigns: CampaignParameters<CampaignType>[], dryRun?: boolean): Promise<unknown[]>;
|
9
9
|
/**
|
10
10
|
* @dev Test function used to create mock ERC20 static campaigns and check tvl and metadata
|
11
11
|
*/
|
@@ -20,5 +20,5 @@ export declare class DynamicDataService {
|
|
20
20
|
/**
|
21
21
|
* @dev Recursive function to handle errors in fetching dynamic data
|
22
22
|
*/
|
23
|
-
static fetchWithRecursiveErrorHandling<R>(fn: (chainId: MerklChainId, campaigns: CampaignParameters<
|
23
|
+
static fetchWithRecursiveErrorHandling<R>(fn: (chainId: MerklChainId, campaigns: CampaignParameters<CampaignType>[]) => Promise<R[]>, campaigns: CampaignParameters<CampaignType>[], chainId: number): Promise<R[]>;
|
24
24
|
}
|
@@ -10,7 +10,7 @@ import { TvlService } from "@/modules/v4/tvl/tvl.service";
|
|
10
10
|
import bigintToString from "@/utils/bigintToString";
|
11
11
|
import { log } from "@/utils/logger";
|
12
12
|
import { AprType } from "@db/api";
|
13
|
-
import { Campaign as
|
13
|
+
import { Campaign as CampaignType, DAY, NETWORK_LABELS, bigIntToNumber, } from "@sdk";
|
14
14
|
import moment from "moment";
|
15
15
|
import { AprService } from "../apr";
|
16
16
|
import { CampaignService } from "../campaign";
|
@@ -38,7 +38,7 @@ export class DynamicDataService {
|
|
38
38
|
const opportunityIds = new Set(records.map(r => OpportunityService.hashId({
|
39
39
|
chainId,
|
40
40
|
identifier: r.campaign.mainParameter,
|
41
|
-
type:
|
41
|
+
type: CampaignType[+type],
|
42
42
|
})));
|
43
43
|
const now = moment().unix();
|
44
44
|
const updates = [];
|
@@ -46,7 +46,7 @@ export class DynamicDataService {
|
|
46
46
|
const recordsForOpportunity = records.filter(r => OpportunityService.hashId({
|
47
47
|
chainId,
|
48
48
|
identifier: r.campaign.mainParameter,
|
49
|
-
type:
|
49
|
+
type: CampaignType[+type],
|
50
50
|
}) === opportunityId);
|
51
51
|
const tvl = {
|
52
52
|
timestamp: BigInt(now),
|
@@ -96,7 +96,7 @@ export class DynamicDataService {
|
|
96
96
|
let campaignDailyValue = await TokenService.getValueByTokenId(TokenService.hashId({ address: rewardTokenAddress, chainId: record.campaign.chainId }), dailyAmount);
|
97
97
|
// Fixed APR campaigns
|
98
98
|
if (hasFixedAprConfig(campaignParameters)) {
|
99
|
-
log.local(`[${NETWORK_LABELS[chainId]}][${
|
99
|
+
log.local(`[${NETWORK_LABELS[chainId]}][${CampaignType[type]}] calculating fixed APR for ${record.campaign.campaignId}`);
|
100
100
|
const { targetTokenPricing, rewardTokenPricing, apr: fixedApr } = campaignParameters;
|
101
101
|
const targetApr = Number(fixedApr);
|
102
102
|
if (targetTokenPricing && rewardTokenPricing) {
|
@@ -182,7 +182,7 @@ export class DynamicDataService {
|
|
182
182
|
});
|
183
183
|
}
|
184
184
|
}
|
185
|
-
log.info(`[${NETWORK_LABELS[chainId]}][${
|
185
|
+
log.info(`[${NETWORK_LABELS[chainId]}][${CampaignType[type]}] updated ${updates.length}/${campaigns.length} campaigns using campaignTVLBuilder`);
|
186
186
|
}
|
187
187
|
return updates;
|
188
188
|
}
|
@@ -192,7 +192,7 @@ export class DynamicDataService {
|
|
192
192
|
for (const data of dynamicData) {
|
193
193
|
if (!!data) {
|
194
194
|
// Main Parameter OVERRIDING
|
195
|
-
if (data.campaignType ===
|
195
|
+
if (data.campaignType === CampaignType.SILO && data.campaignParameters.whitelist?.length === 1)
|
196
196
|
data.mainParameter = `${data.mainParameter}-${data.campaignParameters.whitelist[0]}`;
|
197
197
|
if (!oppMap[`${data.campaignType}_${data.mainParameter}`])
|
198
198
|
oppMap[`${data.campaignType}_${data.mainParameter}`] = {};
|
@@ -207,7 +207,7 @@ export class DynamicDataService {
|
|
207
207
|
const opportunityId = OpportunityService.hashId({
|
208
208
|
chainId,
|
209
209
|
identifier: mainParameter,
|
210
|
-
type:
|
210
|
+
type: CampaignType[+type],
|
211
211
|
});
|
212
212
|
try {
|
213
213
|
if (!dryRun)
|
@@ -218,7 +218,7 @@ export class DynamicDataService {
|
|
218
218
|
}
|
219
219
|
dynamicDataArray.push(bigintToString({ campaignId: Object.values(entry[1])[0].campaignId, apr, tvl, dailyRewards }));
|
220
220
|
}
|
221
|
-
log.info(`[${NETWORK_LABELS[chainId]}][${
|
221
|
+
log.info(`[${NETWORK_LABELS[chainId]}][${CampaignType[type]}] updated ${dynamicData.length}/${campaigns.length} campaigns`);
|
222
222
|
return dynamicDataArray;
|
223
223
|
}
|
224
224
|
/**
|
@@ -252,11 +252,11 @@ export class DynamicDataService {
|
|
252
252
|
symbolTargetToken: "EXT",
|
253
253
|
targetToken: tokenAddress,
|
254
254
|
},
|
255
|
-
campaignType:
|
255
|
+
campaignType: CampaignType.ERC20,
|
256
256
|
},
|
257
257
|
];
|
258
258
|
log.info(`querying mock campaign on chain: ${NETWORK_LABELS[chainId]}`);
|
259
|
-
const result = await dynamicDataBuilderFactory(
|
259
|
+
const result = await dynamicDataBuilderFactory(CampaignType.ERC20).build(Number(chainId), campaigns);
|
260
260
|
return {
|
261
261
|
priceTargetToken: result[0]?.typeInfo.priceTargetToken,
|
262
262
|
totalSupply: result[0]?.typeInfo.totalSupply,
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import { Campaign as
|
1
|
+
import { type CampaignParameters, Campaign as CampaignType, type Opportunity as OpportunityV3 } from "@sdk";
|
2
2
|
import type { CampaignWithParams } from "../campaign";
|
3
3
|
import { OpportunityService } from "./opportunity.service";
|
4
4
|
export declare abstract class OpportunityConvertorService {
|
5
5
|
#private;
|
6
|
-
static convertV4CampaignToV3<C extends
|
6
|
+
static convertV4CampaignToV3<C extends CampaignType>(campaignType: C, campaign: Exclude<Awaited<ReturnType<(typeof OpportunityService)["findMany"]>>[number]["campaigns"], undefined>[number] | Omit<CampaignWithParams<C>, "manualOverrides">, opportunityIdentifier: string): CampaignParameters<C>;
|
7
7
|
static convertV4toV3(opportunity: Awaited<ReturnType<(typeof OpportunityService)["findMany"]>>[number], withCampaigns?: boolean): OpportunityV3;
|
8
8
|
static setV3Opportunities(showCampaigns: boolean, test: boolean | undefined, identifier: string | undefined, chainId: string | undefined): Promise<{}>;
|
9
9
|
static logKeyAndTTLV3Opportunities(showCampaigns: boolean, test: boolean | undefined, identifier: string | undefined, chainId: string | undefined): Promise<void>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { kebabToPascalCase } from "@/utils/caseChanges";
|
2
2
|
import { log } from "@/utils/logger";
|
3
|
-
import { Campaign as
|
3
|
+
import { Campaign as CampaignType, EAprBreakdownType, opportunityActions, } from "@sdk";
|
4
4
|
import moment from "moment";
|
5
5
|
import { CacheService } from "../cache";
|
6
6
|
import { TTLPresets } from "../cache/cache.model";
|
@@ -26,7 +26,7 @@ export class OpportunityConvertorService {
|
|
26
26
|
}
|
27
27
|
static convertV4toV3(opportunity, withCampaigns = false) {
|
28
28
|
const now = moment().unix();
|
29
|
-
const id = `${
|
29
|
+
const id = `${CampaignType[opportunity.type]}_${opportunity.identifier}`; // V3 id
|
30
30
|
// Convert v4 actions to old type
|
31
31
|
let action = opportunity.action.toLowerCase();
|
32
32
|
if (!opportunityActions.includes(action)) {
|
@@ -117,17 +117,17 @@ export class OpportunityConvertorService {
|
|
117
117
|
return acc;
|
118
118
|
}, []) ?? [],
|
119
119
|
campaigns: {
|
120
|
-
type:
|
120
|
+
type: CampaignType[opportunity.type],
|
121
121
|
ids: opportunity.campaigns?.map(campaign => campaign.campaignId) ?? [],
|
122
122
|
active: withCampaigns
|
123
123
|
? opportunity.campaigns
|
124
124
|
?.filter(campaign => campaign.startTimestamp < BigInt(now) && BigInt(now) < campaign.endTimestamp)
|
125
|
-
.map(campaign => OpportunityConvertorService.convertV4CampaignToV3(
|
125
|
+
.map(campaign => OpportunityConvertorService.convertV4CampaignToV3(CampaignType[campaign.type], campaign, opportunity.identifier))
|
126
126
|
: undefined,
|
127
127
|
inactive: withCampaigns
|
128
128
|
? opportunity.campaigns
|
129
129
|
?.filter(campaign => !(campaign.startTimestamp < BigInt(now) && BigInt(now) < campaign.endTimestamp))
|
130
|
-
.map(campaign => OpportunityConvertorService.convertV4CampaignToV3(
|
130
|
+
.map(campaign => OpportunityConvertorService.convertV4CampaignToV3(CampaignType[campaign.type], campaign, opportunity.identifier))
|
131
131
|
: undefined,
|
132
132
|
},
|
133
133
|
};
|
@@ -7,7 +7,7 @@ import { TokenService } from "@/modules/v4/token/token.service";
|
|
7
7
|
import { UserService } from "@/modules/v4/user/user.service";
|
8
8
|
import { log } from "@/utils/logger";
|
9
9
|
import { Status } from "@db/api";
|
10
|
-
import { Campaign as
|
10
|
+
import { Campaign as CampaignType } from "@sdk";
|
11
11
|
import moment from "moment";
|
12
12
|
import { metadataBuilderFactory } from "../../../engine/metadata/factory";
|
13
13
|
import { ProtocolService } from "../protocol/protocol.service";
|
@@ -43,7 +43,7 @@ export class OpportunityService {
|
|
43
43
|
* @param campaign
|
44
44
|
*/
|
45
45
|
static async #getMetadata(campaign, opportunityIdentifier) {
|
46
|
-
const campaignType =
|
46
|
+
const campaignType = CampaignType[campaign.type];
|
47
47
|
return await metadataBuilderFactory(campaignType).build(campaign, opportunityIdentifier);
|
48
48
|
}
|
49
49
|
/**
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { BadRequestError } from "@/errors";
|
2
|
-
import { Campaign as
|
2
|
+
import { Campaign as CampaignType } from "@sdk";
|
3
3
|
export const validateId = ({ params }) => {
|
4
4
|
if (!params.id.includes("-")) {
|
5
5
|
if (/[0-9]{1,20}/.test(params.id))
|
@@ -7,6 +7,6 @@ export const validateId = ({ params }) => {
|
|
7
7
|
throw new BadRequestError("Invalid Opportunity id");
|
8
8
|
}
|
9
9
|
const [_chainId, type, _campaignId] = params.id.split("-");
|
10
|
-
if (!Object.values(
|
11
|
-
throw new BadRequestError("Invalid Campaign type", Object.keys(
|
10
|
+
if (!Object.values(CampaignType).includes(type))
|
11
|
+
throw new BadRequestError("Invalid Campaign type", Object.keys(CampaignType));
|
12
12
|
};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { CacheKeys } from "@/cache/keys";
|
2
2
|
import type { Chain } from "@db/api";
|
3
|
-
import { type CampaignDynamicData, Campaign as
|
3
|
+
import { type CampaignDynamicData, Campaign as CampaignType, type ChainId, type MerklChainId } from "@sdk";
|
4
4
|
import { type LightOpportunityFromDB, type Opportunity } from "../opportunity";
|
5
5
|
import type { CampaignIdModel, CampaignIdWithoutPageModel, CreateManyBreakdownModel, CreateManyRewardModel, DailyRewardsRecord, RegisterClaimsModel, RewardBreakdown, TokenIdModel } from "./reward.model";
|
6
6
|
import { RewardRepository } from "./reward.repository";
|
@@ -785,5 +785,5 @@ export declare abstract class RewardService {
|
|
785
785
|
/**
|
786
786
|
* @deprecated
|
787
787
|
*/
|
788
|
-
static extractDailyRewardsRecordFromDynamicData<C extends
|
788
|
+
static extractDailyRewardsRecordFromDynamicData<C extends CampaignType>(type: C, dynamicData: CampaignDynamicData<C>[], timestamp?: bigint): Promise<DailyRewardsRecord["model"]>;
|
789
789
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { log } from "@/utils/logger";
|
2
|
-
import { Campaign as
|
2
|
+
import { Campaign as CampaignType, DAY, DistributorService, NETWORK_LABELS, } from "@sdk";
|
3
3
|
import moment from "moment";
|
4
4
|
import { BlacklistService } from "../blacklist";
|
5
5
|
import { CacheService } from "../cache";
|
@@ -358,7 +358,7 @@ export class RewardService {
|
|
358
358
|
* @deprecated
|
359
359
|
*/
|
360
360
|
static async extractDailyRewardsRecordFromDynamicData(type, dynamicData, timestamp = BigInt(moment().unix())) {
|
361
|
-
const typesWithoutApr = [
|
361
|
+
const typesWithoutApr = [CampaignType.INVALID];
|
362
362
|
if (typesWithoutApr.includes(type))
|
363
363
|
return { timestamp, total: 0, breakdowns: [] };
|
364
364
|
const breakdowns = [];
|
@@ -2003,8 +2003,8 @@ export declare const v4: Elysia<"/v4", false, {
|
|
2003
2003
|
body: unknown;
|
2004
2004
|
params: {};
|
2005
2005
|
query: {
|
2006
|
+
distributionChain?: number | undefined;
|
2006
2007
|
campaignId: string;
|
2007
|
-
distributionChain: number;
|
2008
2008
|
};
|
2009
2009
|
headers: {
|
2010
2010
|
authorization: string;
|
@@ -114,6 +114,26 @@ export declare abstract class TokenService {
|
|
114
114
|
} & {
|
115
115
|
price?: number | null | undefined;
|
116
116
|
}>;
|
117
|
+
/**
|
118
|
+
* Read token from database, tries to fill it if unexistant
|
119
|
+
* @param chainId
|
120
|
+
* @param address
|
121
|
+
*/
|
122
|
+
static findUniqueFillOrThrow(token: TokenUnique): Promise<{
|
123
|
+
symbol: string;
|
124
|
+
id: string;
|
125
|
+
name: string | null;
|
126
|
+
icon: string;
|
127
|
+
address: string;
|
128
|
+
chainId: number;
|
129
|
+
decimals: number;
|
130
|
+
verified: boolean;
|
131
|
+
isTest: boolean;
|
132
|
+
isPoint: boolean;
|
133
|
+
isNative: boolean;
|
134
|
+
} & {
|
135
|
+
price?: number | null | undefined;
|
136
|
+
}>;
|
117
137
|
/**
|
118
138
|
* Checks if two tokens are the same based on chainId/address combo
|
119
139
|
* @param a token
|
@@ -163,6 +163,25 @@ export class TokenService {
|
|
163
163
|
const id = typeof token === "string" ? token : TokenService.hashId(token);
|
164
164
|
return await TokenRepository.findUniqueOrThrow(id);
|
165
165
|
}
|
166
|
+
/**
|
167
|
+
* Read token from database, tries to fill it if unexistant
|
168
|
+
* @param chainId
|
169
|
+
* @param address
|
170
|
+
*/
|
171
|
+
static async findUniqueFillOrThrow(token) {
|
172
|
+
const id = TokenService.hashId(token);
|
173
|
+
let result = await TokenRepository.findUnique(id);
|
174
|
+
if (!result) {
|
175
|
+
await TokenService.fillAndCreate({
|
176
|
+
chainId: token.chainId,
|
177
|
+
address: token.address,
|
178
|
+
verified: false,
|
179
|
+
icon: "",
|
180
|
+
});
|
181
|
+
result = await TokenRepository.findUniqueOrThrow(id);
|
182
|
+
}
|
183
|
+
return result;
|
184
|
+
}
|
166
185
|
/**
|
167
186
|
* Checks if two tokens are the same based on chainId/address combo
|
168
187
|
* @param a token
|
@@ -2,7 +2,7 @@ import { Redis } from "@/cache";
|
|
2
2
|
import { CampaignService } from "@/modules/v4/campaign";
|
3
3
|
import { OpportunityConvertorService } from "@/modules/v4/opportunity/opportunity.converter";
|
4
4
|
import { UnsupportedNetwork } from "@/utils/error";
|
5
|
-
import { ANGLE_NETWORKS, Campaign as
|
5
|
+
import { ANGLE_NETWORKS, Campaign as CampaignType, ChainId, isSupportedChain, registry, } from "@sdk";
|
6
6
|
import { t } from "elysia";
|
7
7
|
export const query = t.Object({
|
8
8
|
chainIds: t.Optional(t.Union([t.String(), t.Array(t.String())])),
|
@@ -72,7 +72,7 @@ export default (app) => app.get("/campaigns", async ({ query }) => {
|
|
72
72
|
if (process.env.FF_OPPORTUNITY === "true") {
|
73
73
|
const campaigns = await CampaignService.findMany({
|
74
74
|
distributionChainIds: chainIds,
|
75
|
-
types: !types.length ? undefined : types.map(type =>
|
75
|
+
types: !types.length ? undefined : types.map(type => CampaignType[type]),
|
76
76
|
status: query.live ? "LIVE" : undefined,
|
77
77
|
creatorTag: query.creatorTag,
|
78
78
|
test: !hideTestTokens,
|
@@ -84,7 +84,7 @@ export default (app) => app.get("/campaigns", async ({ query }) => {
|
|
84
84
|
res[campaign.distributionChainId] = {};
|
85
85
|
}
|
86
86
|
const opportunityIdentifier = campaign.Opportunity.identifier;
|
87
|
-
const campaignType =
|
87
|
+
const campaignType = CampaignType[campaign.type];
|
88
88
|
if (!res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`]) {
|
89
89
|
res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`] = {
|
90
90
|
...OpportunityConvertorService.convertV4CampaignToV3(campaignType, campaign, opportunityIdentifier),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { NotFoundError } from "@/errors";
|
2
2
|
import { OpportunityService } from "@/modules/v4/opportunity";
|
3
|
-
import { BN2Number, Campaign as
|
3
|
+
import { BN2Number, Campaign as CampaignType } from "@sdk";
|
4
4
|
import { t } from "elysia";
|
5
5
|
import checkQueryChainIdValidity from "../../hooks/checkQueryChainIdValidity";
|
6
6
|
export const query = t.Object({
|
@@ -19,7 +19,7 @@ export default (app) => app.use(checkQueryChainIdValidity()).get("/campaignsForM
|
|
19
19
|
return (await OpportunityService.getUniqueWithCampaignsOrThrow(opportunityId))?.campaigns
|
20
20
|
?.map(c => ({
|
21
21
|
campaignId: c.campaignId,
|
22
|
-
campaignType:
|
22
|
+
campaignType: CampaignType[c.type],
|
23
23
|
rewardToken: c.rewardToken.address,
|
24
24
|
rewardTokenSymbol: c.rewardToken.symbol,
|
25
25
|
amountDecimal: BN2Number(c.amount, c.rewardToken.decimals),
|