@merkl/api 0.20.89 → 0.20.90

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.
@@ -75,16 +75,23 @@ export class EventBasedDynamicData {
75
75
  const isLive = moment().unix() > startTimestamp && moment().unix() < endTimestamp;
76
76
  let distributionMeanAPR = 0;
77
77
  const priceRewardToken = await TokenService.getRewardTokenPrice(campaign);
78
+ const rewardTokens = await TokenService.findManyOrCreate([
79
+ { chainId: campaign.chainId, address: campaign.rewardToken },
80
+ ]);
81
+ const rewardToken = rewardTokens[0];
78
82
  const tvl = distributedRewards / multiplier;
79
83
  if (isLive) {
80
84
  /** Yearly rewards in $ */
81
- const fixRewardRate = multiplier * priceRewardToken;
82
- distributionMeanAPR = fixRewardRate;
85
+ let fixRewardRate = multiplier * priceRewardToken;
83
86
  if (distributedRewards > (amount * (moment().unix() - startTimestamp)) / (endTimestamp - startTimestamp)) {
84
- distributionMeanAPR =
87
+ fixRewardRate =
85
88
  (fixRewardRate * amount * (moment().unix() - startTimestamp)) / (endTimestamp - startTimestamp) / tvl;
86
89
  }
90
+ distributionMeanAPR = fixRewardRate * 365 * 100;
87
91
  distributionMeanAPR = !distributionMeanAPR || Number.isNaN(distributionMeanAPR) ? 0 : distributionMeanAPR;
92
+ if (rewardToken.isPoint) {
93
+ distributionMeanAPR = distributionMeanAPR / 365 / 100;
94
+ }
88
95
  dynamicData.push({
89
96
  ...campaign,
90
97
  apr: distributionMeanAPR,
@@ -280,9 +280,6 @@ export class CampaignService {
280
280
  static format(campaign) {
281
281
  const { DistributionChain, ComputeChain, Creator, RewardToken, params, CampaignStatus, createdAt, manualOverrides: _, ...c } = campaign;
282
282
  const updatedParams = params;
283
- if (ComputeChain.name === "Etherlink") {
284
- updatedParams.blacklist = [];
285
- }
286
283
  return {
287
284
  ...c,
288
285
  params: updatedParams,
@@ -1,6 +1,7 @@
1
1
  import { HttpErrorDto, NotFoundError, NotFoundErrorDto } from "@/errors";
2
2
  import { BackOfficeGuard } from "@/guards/BackOffice.guard";
3
3
  import { AuthorizationHeadersDto, TokenAuthGuard } from "@/guards/TokenAuth.guard";
4
+ import { ChainId } from "@sdk";
4
5
  import Elysia, { t } from "elysia";
5
6
  import { GetCampaignQueryDto } from "../campaign";
6
7
  import { CreateOpportunityDto, GetOpportunitiesQueryDto, GetOpportunityQueryDto, OpportunityAggregateFieldDto, OpportunityDeleteOverrideDto, OpportunityOverrideDto, OpportunityResourceDto, OpportunityUniqueDto, OpportunityUniqueUpdateDto, OpportunityWithCampaignsResourceDto, } from "./opportunity.model";
@@ -119,11 +120,23 @@ export const OpportunityController = new Elysia({
119
120
  if (!params.id.includes("-"))
120
121
  return await OpportunityService.getUniqueWithCampaignsOrThrow(params.id, query.test ?? false, query.point ?? false);
121
122
  const [chainId, type, identifier] = params.id.split("-");
122
- return await OpportunityService.getUniqueWithCampaignsOrThrow({
123
+ const response = await OpportunityService.getUniqueWithCampaignsOrThrow({
123
124
  chainId: +chainId,
124
125
  type: type,
125
126
  identifier,
126
127
  }, query.test ?? false, query.point ?? false);
128
+ if (response.chainId === ChainId.ETHERLINK) {
129
+ const campaigns = response.campaigns;
130
+ for (let campaign of Object.values(campaigns)) {
131
+ const updatedParams = campaign.params;
132
+ updatedParams.blacklist = [];
133
+ campaign = {
134
+ ...campaign,
135
+ params: updatedParams,
136
+ };
137
+ }
138
+ }
139
+ return response;
127
140
  }
128
141
  catch (err) {
129
142
  if (err.code && err.code === "P2025")
@@ -107,7 +107,7 @@ export class OpportunityService {
107
107
  const sortedCampaigns = opportunity?.Campaigns.filter(campaign => campaignId ? campaign.campaignId === campaignId : true).sort((a, b) => Number(b.endTimestamp) - Number(a.endTimestamp));
108
108
  let firstCampaign = sortedCampaigns[0];
109
109
  const firstCampaigns = sortedCampaigns.filter(campaign => campaign.startTimestamp <= BigInt(moment().unix()));
110
- if (firstCampaigns.length >= 0)
110
+ if (firstCampaigns.length > 0)
111
111
  firstCampaign = firstCampaigns[0];
112
112
  return await OpportunityService.createFromCampaign({
113
113
  ...firstCampaign,