@merkl/api 0.20.75 → 0.20.77

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.
@@ -1,5 +1,6 @@
1
1
  import { CampaignService } from "@/modules/v4/campaign/campaign.service";
2
2
  import { TokenService } from "@/modules/v4/token/token.service";
3
+ import { CannotUpdateOpportunityLastCreatedAt } from "@/utils/error";
3
4
  import { log } from "@/utils/logger";
4
5
  import { apiDbClient, engineDbClient } from "@db";
5
6
  import { Prisma, RunStatus } from "@db/api";
@@ -203,6 +204,15 @@ export class CampaignRepository {
203
204
  identifier: campaign.opportunityIdentifier,
204
205
  type: campaignType,
205
206
  });
207
+ // If the campaign is being created, update the lastCampaignCreatedAt field in the opportunity
208
+ if (!previousCampaign) {
209
+ try {
210
+ await OpportunityService.update(opportunityId, { lastCampaignCreatedAt: new Date() });
211
+ }
212
+ catch {
213
+ throw new CannotUpdateOpportunityLastCreatedAt(campaign.campaignId, campaign.chainId, campaign.type);
214
+ }
215
+ }
206
216
  const data = {
207
217
  id: campaign.id,
208
218
  amount: campaign.amount,
@@ -3,12 +3,11 @@ import { OpportunityService } from "@/modules/v4/opportunity";
3
3
  import { StatusService } from "@/modules/v4/status/status.service";
4
4
  import { TokenRepository } from "@/modules/v4/token/token.repository";
5
5
  import { TokenService } from "@/modules/v4/token/token.service";
6
- import { CannotParseOpportunity, CannotUpdateOpportunityLastCreatedAt, InvalidParameter } from "@/utils/error";
6
+ import { CannotParseOpportunity, InvalidParameter } from "@/utils/error";
7
7
  import { log } from "@/utils/logger";
8
8
  import { Campaign as CampaignEnum, NETWORK_LABELS, } from "@sdk";
9
9
  import { utils } from "ethers";
10
10
  import moment from "moment";
11
- import { OpportunityRepository } from "../opportunity/opportunity.repository";
12
11
  import { CampaignRepository } from "./campaign.repository";
13
12
  export class CampaignService {
14
13
  static hashId(campaign) {
@@ -41,14 +40,6 @@ export class CampaignService {
41
40
  console.error(e);
42
41
  throw new CannotParseOpportunity(campaign.campaignId, campaign.chainId, campaign.type);
43
42
  }
44
- if (!!CampaignRepository.findUnique(id)) {
45
- try {
46
- await OpportunityRepository.update(id, { lastCampaignCreatedAt: new Date() });
47
- }
48
- catch {
49
- throw new CannotUpdateOpportunityLastCreatedAt(campaign.campaignId, campaign.chainId, campaign.type);
50
- }
51
- }
52
43
  return await CampaignRepository.upsert({ id, ...campaign });
53
44
  }
54
45
  /**
@@ -89,7 +89,7 @@ export class UniswapService {
89
89
  fromBlock = await getContractCreationBlock(poolManagerAddress, jsonRPCprovider);
90
90
  }
91
91
  if (fromBlock < 0) {
92
- fromBlock = 0;
92
+ fromBlock = 1;
93
93
  }
94
94
  const toBlock = await jsonRPCprovider.getBlockNumber();
95
95
  const logs = await safeFetchLogs(chainId, // TODO: rm type enforcing