@merkl/api 0.10.139 → 0.10.140

Sign up to get free protection for your applications and to get access to all the features.
@@ -254,7 +254,19 @@ export declare abstract class OpportunityRepository {
254
254
  dailyRewards: number;
255
255
  }>;
256
256
  static findManyWithCampaigns(filters: Prisma.OpportunityFindManyArgs): Promise<({
257
- Campaigns: {
257
+ Campaigns: ({
258
+ RewardToken: {
259
+ symbol: string;
260
+ name: string | null;
261
+ id: string;
262
+ chainId: number;
263
+ address: string;
264
+ icon: string;
265
+ decimals: number;
266
+ verified: boolean;
267
+ price: number | null;
268
+ };
269
+ } & {
258
270
  type: import("../../../../database/api/.generated").$Enums.CampaignType;
259
271
  id: string;
260
272
  params: Prisma.JsonValue;
@@ -268,7 +280,7 @@ export declare abstract class OpportunityRepository {
268
280
  amount: string;
269
281
  opportunityId: string;
270
282
  creatorAddress: string;
271
- }[];
283
+ })[];
272
284
  } & {
273
285
  name: string;
274
286
  type: import("../../../../database/api/.generated").$Enums.CampaignType;
@@ -462,6 +474,20 @@ export declare abstract class OpportunityRepository {
462
474
  apr: number;
463
475
  dailyRewards: number;
464
476
  }>;
477
+ static updateName(id: string, name: string): Promise<{
478
+ name: string;
479
+ type: import("../../../../database/api/.generated").$Enums.CampaignType;
480
+ id: string;
481
+ status: import("../../../../database/api/.generated").$Enums.Status;
482
+ tags: string[];
483
+ identifier: string;
484
+ chainId: number;
485
+ action: import("../../../../database/api/.generated").$Enums.OpportunityAction;
486
+ mainProtocolId: string | null;
487
+ tvl: number;
488
+ apr: number;
489
+ dailyRewards: number;
490
+ }>;
465
491
  static aggregateSum(field: keyof Prisma.OpportunitySumAggregateInputType, query: GetOpportunitiesQueryEntity): Promise<{
466
492
  sum: never;
467
493
  }>;
@@ -93,7 +93,19 @@ export class OpportunityRepository {
93
93
  });
94
94
  }
95
95
  static async findManyWithCampaigns(filters) {
96
- return await apiDbClient.opportunity.findMany({ ...filters, include: { Campaigns: true } });
96
+ return await apiDbClient.opportunity.findMany({
97
+ ...filters,
98
+ include: {
99
+ Campaigns: {
100
+ include: {
101
+ RewardToken: true,
102
+ },
103
+ orderBy: {
104
+ endTimestamp: "desc",
105
+ },
106
+ },
107
+ },
108
+ });
97
109
  }
98
110
  static #transformQueryToPrismaFilters(query) {
99
111
  const { page: _page, items: _items, ...filters } = query;
@@ -215,6 +227,9 @@ export class OpportunityRepository {
215
227
  return await apiDbClient.opportunity.update({ where: { id }, data: { status, apr: 0, dailyRewards: 0 } });
216
228
  return await apiDbClient.opportunity.update({ where: { id }, data: { status } });
217
229
  }
230
+ static async updateName(id, name) {
231
+ return await apiDbClient.opportunity.update({ where: { id }, data: { name } });
232
+ }
218
233
  static async aggregateSum(field, query) {
219
234
  const args = OpportunityRepository.#transformQueryToPrismaFilters(query);
220
235
  const result = await apiDbClient.opportunity.aggregate({
@@ -1,6 +1,6 @@
1
1
  import { type CreateCampaignModel } from "../campaign";
2
2
  import { Prisma } from "../../../../database/api/.generated";
3
- import type { ChainId } from "@sdk";
3
+ import { type ChainId } from "@sdk";
4
4
  import type { CreateOpportunityModel, GetOpportunitiesQueryEntity, LightOpportunityFromDB, OpportunityMetadata, OpportunityUnique } from "./opportunity.model";
5
5
  import { OpportunityRepository } from "./opportunity.repository";
6
6
  export declare abstract class OpportunityService {
@@ -17,6 +17,7 @@ export declare abstract class OpportunityService {
17
17
  * @returns {OpportunityMetadata}
18
18
  */
19
19
  static getMetadata(campaign: CreateCampaignModel): Promise<OpportunityMetadata>;
20
+ static updateNames(): Promise<void>;
20
21
  static updateMetadata(chain: ChainId): Promise<void>;
21
22
  static getUniqueWithCampaignsOrThrow(opportunityId: string | OpportunityUnique): Promise<({
22
23
  aprRecord: {
@@ -3,6 +3,7 @@ import { CampaignService } from "../campaign";
3
3
  import { log } from "../../../utils/logger";
4
4
  import { OpportunityAction, Prisma } from "../../../../database/api/.generated";
5
5
  import { record } from "@elysiajs/opentelemetry";
6
+ import { Campaign } from "@sdk";
6
7
  import { CacheService } from "../cache";
7
8
  import { TTLPresets } from "../cache/cache.model";
8
9
  import { OpportunityRepository } from "./opportunity.repository";
@@ -75,6 +76,35 @@ export class OpportunityService {
75
76
  throw "UNKNOWN CAMPAIGN TYPE";
76
77
  }
77
78
  }
79
+ static async updateNames() {
80
+ const opportunities = await OpportunityRepository.findManyWithCampaigns({});
81
+ log.info(`updating ${opportunities.length} opportunities names`);
82
+ for (const [i, opp] of opportunities.entries()) {
83
+ try {
84
+ const campaignData = opp.Campaigns[0];
85
+ const campaign = {
86
+ ...campaignData,
87
+ creator: campaignData.creatorAddress,
88
+ chainId: campaignData.distributionChainId,
89
+ rewardTokenAddress: campaignData.RewardToken.address,
90
+ opportunityIdentifier: opp.identifier,
91
+ subType: campaignData.subType ?? undefined,
92
+ type: Campaign[campaignData.type],
93
+ params: JSON.stringify(campaignData.params),
94
+ startTimestamp: campaignData.startTimestamp.toString(),
95
+ endTimestamp: campaignData.endTimestamp.toString(),
96
+ };
97
+ const metadata = await OpportunityService.getMetadata(campaign);
98
+ if (opp.name !== metadata.name) {
99
+ log.info(`updating opportunity ${opp.id} name from ${opp.name} to ${metadata.name}`);
100
+ await OpportunityRepository.updateName(opp.id, metadata.name);
101
+ }
102
+ }
103
+ catch (err) {
104
+ log.error(`failed to update opportunity ${opp.id} name`, err);
105
+ }
106
+ }
107
+ }
78
108
  static async updateMetadata(chain) {
79
109
  try {
80
110
  const opportunities = await OpportunityRepository.findManyWithCampaigns({
@@ -22,7 +22,7 @@ export const getClammMetadata = (chainId, params) => {
22
22
  platform = "iZUMi";
23
23
  }
24
24
  return {
25
- name: [platform, `${params.symbolToken0}/${params.symbolToken1}`, params.poolFee && `${params.poolFee}%`].join(" "),
25
+ name: `Provide liquidity to ${params.symbolToken0}-${params.symbolToken1}${params.poolFee ? ` ${params.poolFee}%` : ""}`,
26
26
  action: OpportunityAction.POOL,
27
27
  tokens: [
28
28
  { chainId, address: params.token0 },
@@ -1,7 +1,7 @@
1
1
  import { OpportunityAction } from "../../../../../database/api/.generated";
2
2
  export const getDolomiteMetadata = (chainId, campaignSubType, params) => {
3
3
  const subtypes = [
4
- { name: "Delta", action: OpportunityAction.LEND },
4
+ { name: "Supply (delta)", action: OpportunityAction.LEND },
5
5
  { name: "Supply", action: OpportunityAction.LEND },
6
6
  { name: "Borrow", action: OpportunityAction.BORROW },
7
7
  ];
@@ -1,7 +1,7 @@
1
1
  import { OpportunityAction } from "../../../../../database/api/.generated";
2
2
  export const getErc20SnapshotMetadata = (chainId, params) => {
3
3
  return {
4
- name: ["Airdrop", params.symbolTargetToken, "holders"].join(" "),
4
+ name: ["Get", params.symbolTargetToken, "airdrop"].join(" "),
5
5
  action: OpportunityAction.DROP,
6
6
  tokens: [{ chainId, address: params.targetToken }],
7
7
  };
@@ -3,9 +3,9 @@ import { OpportunityAction } from "../../../../../database/api/.generated";
3
3
  export const getJsonAirdropMetadata = async (chainId, creator, params) => {
4
4
  const ACI = "0xdeadD8aB03075b7FBA81864202a2f59EE25B312b".toLowerCase();
5
5
  const aaveDAO = "0x5300A1a15135EA4dc7aD5a167152C01EFc9b192A".toLowerCase();
6
- const aciPrefix = creator.toLowerCase() === ACI && "Aave Merit Rewards -";
7
- const aavePrefix = creator.toLowerCase() === aaveDAO && "Aave - aAMPL distribution -";
8
- const prefix = aavePrefix ? aavePrefix : aciPrefix ? aciPrefix : "Airdrop in";
6
+ const aciPrefix = creator.toLowerCase() === ACI && "Get Merit rewards -";
7
+ const aavePrefix = creator.toLowerCase() === aaveDAO && "Get aAMPL distribution -";
8
+ const prefix = aavePrefix ? aavePrefix : aciPrefix ? aciPrefix : "Get airdrop in";
9
9
  let tokenAddress;
10
10
  try {
11
11
  const res = await fetch(params.jsonUrl);
@@ -4,10 +4,10 @@ export const getMorphoMetadata = (chainId, campaignSubType, params) => {
4
4
  const morphoParams = params;
5
5
  const market = `${morphoParams.symbolLoanToken}/${morphoParams.symbolBorrowToken} ${morphoParams?.LLTV && BN2Number(morphoParams?.LLTV, 16)}%`;
6
6
  const subtypes = [
7
- { name: `Metamorpho ${morphoParams.nameTargetToken}`, action: OpportunityAction.LEND },
7
+ { name: `Deposit in ${morphoParams.nameTargetToken} - Metamorpho`, action: OpportunityAction.LEND },
8
8
  { name: `Supply ${morphoParams.symbolLoanToken} on ${market}`, action: OpportunityAction.LEND },
9
9
  { name: `Borrow ${morphoParams.symbolLoanToken} on ${market}`, action: OpportunityAction.BORROW },
10
- { name: `Collateral ${morphoParams.symbolBorrowToken} on ${market}`, action: OpportunityAction.LEND },
10
+ { name: `Lend ${morphoParams.symbolBorrowToken} on ${market}`, action: OpportunityAction.LEND },
11
11
  ];
12
12
  const subtype = subtypes[campaignSubType];
13
13
  return {
@@ -2,7 +2,7 @@ import { OpportunityAction } from "../../../../../database/api/.generated";
2
2
  export const getRadiantMetadata = (chainId, campaignSubType, params) => {
3
3
  return {
4
4
  action: campaignSubType <= 1 ? OpportunityAction.LEND : OpportunityAction.BORROW,
5
- name: ["Radiant", params.symbolTargetToken].join(" "),
5
+ name: [campaignSubType <= 1 ? "Lend" : "Borrow", params.symbolTargetToken].join(" "),
6
6
  tokens: [{ chainId, address: params.targetToken }],
7
7
  mainProtocol: "radiant",
8
8
  };
@@ -6,7 +6,7 @@ export const getSiloMetadata = (chainId, campaignSubType, params) => {
6
6
  suffix += ` (${assetSymbol} Market)`;
7
7
  return {
8
8
  action: campaignSubType <= 1 ? OpportunityAction.LEND : OpportunityAction.BORROW,
9
- name: ["Silo", params.symbolTargetToken, suffix].join(" "),
9
+ name: [campaignSubType <= 1 ? "Lend" : "Borrow", params.symbolTargetToken, suffix].join(" "),
10
10
  tokens: [{ chainId, address: params.targetToken }],
11
11
  mainProtocol: "silo",
12
12
  };