@merkl/api 0.18.12 → 0.18.14

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.
Files changed (27) hide show
  1. package/dist/src/cache/index.d.ts +9 -0
  2. package/dist/src/cache/index.js +12 -3
  3. package/dist/src/eden/index.d.ts +31 -9
  4. package/dist/src/index.d.ts +7 -3
  5. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/implementations/xU308Processor.d.ts +2 -2
  6. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/implementations/xU308Processor.js +9 -9
  7. package/dist/src/libs/staticCampaigns.d.ts +5 -0
  8. package/dist/src/libs/staticCampaigns.js +5 -0
  9. package/dist/src/modules/v4/claims/claims.service.js +1 -2
  10. package/dist/src/modules/v4/enso/enso.service.js +2 -2
  11. package/dist/src/modules/v4/opportunity/opportunity.controller.d.ts +5 -0
  12. package/dist/src/modules/v4/opportunity/opportunity.model.d.ts +1 -0
  13. package/dist/src/modules/v4/opportunity/opportunity.model.js +3 -0
  14. package/dist/src/modules/v4/opportunity/opportunity.repository.js +8 -2
  15. package/dist/src/modules/v4/programPayload/programPayload.repository.js +3 -9
  16. package/dist/src/modules/v4/router.d.ts +5 -0
  17. package/dist/src/modules/v4/status/status.service.js +4 -2
  18. package/dist/src/modules/v4/token/token.service.js +10 -1
  19. package/dist/src/routes/v3/campaigns.d.ts +2 -3
  20. package/dist/src/routes/v3/campaigns.js +59 -21
  21. package/dist/src/routes/v3/router.d.ts +2 -3
  22. package/dist/src/utils/prices/priceService.js +1 -1
  23. package/dist/src/utils/prices/services/erc4626Service.js +1 -1
  24. package/dist/src/utils/throw.d.ts +18 -1
  25. package/dist/src/utils/throw.js +17 -0
  26. package/dist/tsconfig.package.tsbuildinfo +1 -1
  27. package/package.json +1 -5
@@ -1,3 +1,5 @@
1
+ import { Redis } from "@/cache";
2
+ import { removeTestTokens } from "@/entities/campaign";
1
3
  import { CampaignService } from "@/modules/v4/campaign";
2
4
  import { OpportunityConvertorService } from "@/modules/v4/opportunity/opportunity.converter";
3
5
  import { ANGLE_NETWORKS, Campaign as CampaignEnum, ChainId, isSupportedChain, registry, } from "@sdk";
@@ -68,30 +70,66 @@ export default (app) => app.get("/campaigns", async ({ query }) => {
68
70
  throw new UnsupportedNetwork(chainId);
69
71
  }
70
72
  }
71
- const campaigns = await CampaignService.findMany({
72
- distributionChainIds: chainIds,
73
- types: !types.length ? undefined : types.map(type => CampaignEnum[type]),
74
- status: query.live ? "LIVE" : undefined,
75
- creatorTag: query.creatorTag,
76
- test: !hideTestTokens,
77
- withOpportunity: true,
78
- });
79
- const res = {};
80
- for (const campaign of campaigns) {
81
- if (!res[campaign.distributionChainId]) {
82
- res[campaign.distributionChainId] = {};
73
+ if (process.env.FF_OPPORTUNITY === "true") {
74
+ const campaigns = await CampaignService.findMany({
75
+ distributionChainIds: chainIds,
76
+ types: !types.length ? undefined : types.map(type => CampaignEnum[type]),
77
+ status: query.live ? "LIVE" : undefined,
78
+ creatorTag: query.creatorTag,
79
+ test: !hideTestTokens,
80
+ withOpportunity: true,
81
+ });
82
+ const res = {};
83
+ for (const campaign of campaigns) {
84
+ if (!res[campaign.distributionChainId]) {
85
+ res[campaign.distributionChainId] = {};
86
+ }
87
+ const opportunityIdentifier = campaign.Opportunity.identifier;
88
+ const campaignType = CampaignEnum[campaign.type];
89
+ if (!res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`]) {
90
+ res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`] = {
91
+ ...OpportunityConvertorService.convertV4CampaignToV3(campaignType, campaign, opportunityIdentifier),
92
+ apr: campaign.Opportunity.apr,
93
+ tvl: campaign.Opportunity.tvl,
94
+ };
95
+ }
83
96
  }
84
- const opportunityIdentifier = campaign.Opportunity.identifier;
85
- const campaignType = CampaignEnum[campaign.type];
86
- if (!res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`]) {
87
- res[campaign.distributionChainId][`${campaignType}_${opportunityIdentifier}`] = {
88
- ...OpportunityConvertorService.convertV4CampaignToV3(campaignType, campaign, opportunityIdentifier),
89
- apr: campaign.Opportunity.apr,
90
- tvl: campaign.Opportunity.tvl,
91
- };
97
+ return res;
98
+ }
99
+ const campaignCachePrefix = query.live === true ? "LiveCampaigns" : "Campaigns";
100
+ const dynamicData = (await Redis.getManyWithArgs(campaignCachePrefix, chainIds)).reduce((prev, allData, index) => {
101
+ if (!!allData) {
102
+ prev[chainIds[index]] = Object.keys(allData).reduce((acc, curr) => {
103
+ if ((types.length === 0 || types.includes(Number.parseInt(curr.split("_")[0]))) &&
104
+ (!hideTestTokens || removeTestTokens(allData[curr]))) {
105
+ acc[curr] = allData[curr];
106
+ }
107
+ return acc;
108
+ }, {});
109
+ }
110
+ return prev;
111
+ }, {});
112
+ // Remove everything that doesn't contain the creator tag
113
+ if (!!query.creatorTag) {
114
+ for (const c of Object.keys(dynamicData)) {
115
+ for (const type_mainParam of Object.keys(dynamicData[c])) {
116
+ for (const campaignId of Object.keys(dynamicData[c][type_mainParam])) {
117
+ if (!dynamicData[c][type_mainParam][campaignId]?.tags?.includes(query.creatorTag)) {
118
+ delete dynamicData[c][type_mainParam][campaignId];
119
+ }
120
+ }
121
+ // Delete the type_mainParam if it's empty
122
+ if (Object.keys(dynamicData[c][type_mainParam]).length === 0) {
123
+ delete dynamicData[c][type_mainParam];
124
+ }
125
+ }
126
+ // Delete the c if it's empty
127
+ if (Object.keys(dynamicData[c]).length === 0) {
128
+ delete dynamicData[c];
129
+ }
92
130
  }
93
131
  }
94
- return res;
132
+ return dynamicData;
95
133
  }, {
96
134
  query,
97
135
  tags: ["Campaigns"],
@@ -82,9 +82,8 @@ export declare const v3: Elysia<"/v3", false, {
82
82
  };
83
83
  headers: unknown;
84
84
  response: {
85
- 200: {
86
- [x: string]: Record<string, any>;
87
- };
85
+ [x: string]: any;
86
+ 200: any;
88
87
  };
89
88
  };
90
89
  };
@@ -26,7 +26,7 @@ export default class PriceService {
26
26
  });
27
27
  };
28
28
  async fetchPrices() {
29
- const tokenPriceSources = await PriceSourceService.findManyPriceSources();
29
+ const tokenPriceSources = await PriceSourceService.findManyPriceSources({});
30
30
  /**
31
31
  * @description Factory pricer's call to get prices from different sources
32
32
  */
@@ -22,7 +22,7 @@ export default class ERC4626Service {
22
22
  return res;
23
23
  });
24
24
  const resolvedPrices = await Promise.all(pricePromises);
25
- return resolvedPrices.flat().filter(price => price !== undefined);
25
+ return resolvedPrices.flat().filter(price => price !== undefined && price !== null);
26
26
  }
27
27
  async priceCalculation(rate, vaultToken) {
28
28
  try {
@@ -1,4 +1,21 @@
1
1
  import { type ChainId } from "@sdk";
2
+ /**
3
+ * Use this function to throw an error if the address is invalid
4
+ * and normalize the address to its checksum version
5
+ *
6
+ * @dev Usage: params.address = throwOnInvalidAddress(params.address);
7
+ */
2
8
  export declare const throwOnInvalidRequiredAddress: (address: string) => string;
3
- export declare const throwOnInvalidAddress: (address: string) => string | undefined;
9
+ /**
10
+ * Use this function to throw an error if the address is invalid
11
+ * and normalize the address to its checksum version
12
+ *
13
+ * Address can be null or undefined
14
+ *
15
+ * @dev Usage: params.address = throwOnInvalidAddress(params.address);
16
+ */
17
+ export declare const throwOnInvalidAddress: (address: string | undefined) => string | undefined;
18
+ /**
19
+ * Use this function to throw an error if the chainId is not supported by Merkl
20
+ */
4
21
  export declare const throwOnUnsupportedChainId: (chainId: ChainId) => void;
@@ -1,6 +1,12 @@
1
1
  import { isSupportedChain } from "@sdk";
2
2
  import { utils } from "ethers";
3
3
  import { InvalidParameter, UnsupportedNetwork } from "./error";
4
+ /**
5
+ * Use this function to throw an error if the address is invalid
6
+ * and normalize the address to its checksum version
7
+ *
8
+ * @dev Usage: params.address = throwOnInvalidAddress(params.address);
9
+ */
4
10
  export const throwOnInvalidRequiredAddress = (address) => {
5
11
  try {
6
12
  if (!address)
@@ -11,6 +17,14 @@ export const throwOnInvalidRequiredAddress = (address) => {
11
17
  throw new InvalidParameter(`Address ${address} is invalid`);
12
18
  }
13
19
  };
20
+ /**
21
+ * Use this function to throw an error if the address is invalid
22
+ * and normalize the address to its checksum version
23
+ *
24
+ * Address can be null or undefined
25
+ *
26
+ * @dev Usage: params.address = throwOnInvalidAddress(params.address);
27
+ */
14
28
  export const throwOnInvalidAddress = (address) => {
15
29
  try {
16
30
  if (!address)
@@ -21,6 +35,9 @@ export const throwOnInvalidAddress = (address) => {
21
35
  throw new InvalidParameter(`Address ${address} is invalid`);
22
36
  }
23
37
  };
38
+ /**
39
+ * Use this function to throw an error if the chainId is not supported by Merkl
40
+ */
24
41
  export const throwOnUnsupportedChainId = (chainId) => {
25
42
  if (chainId && !isSupportedChain(chainId, "merkl"))
26
43
  throw new UnsupportedNetwork(chainId);