@merkl/api 0.20.108 → 0.20.109

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/package.json CHANGED
@@ -110,5 +110,5 @@
110
110
  "access": "public",
111
111
  "registry": "https://registry.npmjs.org/"
112
112
  },
113
- "version": "v0.20.108"
113
+ "version": "v0.20.109"
114
114
  }
@@ -1,58 +0,0 @@
1
- import { Campaign, type CampaignDynamicData, type ChainId, type Opportunity, type OpportunityId } from "@sdk";
2
- import type { PerChain } from "../types/utils";
3
- export declare const activeCampaign: <C extends ValidCampaign>(v: CampaignDynamicData<C>) => boolean;
4
- export declare const inactiveCampaign: <C extends ValidCampaign>(v: CampaignDynamicData<C>) => boolean;
5
- export declare const removeTestTokens: <C extends ValidCampaign>(v: CampaignDynamicData<C>) => boolean;
6
- export type ValidCampaign = Exclude<Campaign, Campaign.INVALID>;
7
- export type Campaigns = {
8
- [type_mainParameter: string]: {
9
- [campaignId: string]: CampaignDynamicData<Campaign>;
10
- };
11
- };
12
- export declare function getCampaignsFor(chainIds: ChainId[], filters?: {
13
- onlyLive: boolean;
14
- types?: number[];
15
- }): Promise<Campaigns>;
16
- /**
17
- * @returns all opportunityIds in the campaign data
18
- */
19
- export declare function extractIds(campaigns: PerChain<Campaigns>): OpportunityId<ChainId>[];
20
- /**
21
- * @returns the daily price of all rewards from the campaign array
22
- */
23
- export declare function getDailyRewards<C extends ValidCampaign>(campaigns: CampaignDynamicData<C>[], prices: {
24
- [token: string]: number;
25
- }): number;
26
- /**
27
- * @returns the status of an opportunity based on its campaigns
28
- */
29
- export declare function getStatus<C extends ValidCampaign>(campaigns: CampaignDynamicData<C>[]): Opportunity["status"];
30
- /**
31
- * @returns the sum of the APRs from a campaigns array
32
- */
33
- export declare function getApr<C extends Exclude<ValidCampaign, Campaign.ERC20_SNAPSHOT | Campaign.JSON_AIRDROP>>(campaigns: CampaignDynamicData<C>[]): number;
34
- /**
35
- * @returns the sum of the all tags
36
- */
37
- export declare function getTags(campaigns: CampaignDynamicData<ValidCampaign>[]): string[] | undefined;
38
- /**
39
- * @returns all the reward token symbols from a compaign array
40
- */
41
- export declare function getRewardTokenIcons(campaigns: CampaignDynamicData<ValidCampaign>[]): string[];
42
- /**
43
- * @returns the daily reward token symbols from a compaign array
44
- */
45
- export declare function getRewardTokens(campaigns: CampaignDynamicData<ValidCampaign>[]): {
46
- symbol: string;
47
- address: string;
48
- amount: string;
49
- }[];
50
- /**
51
- * @returns campaigns that match the opportunityIds
52
- */
53
- export declare function splitCampaigns(campaigns: PerChain<Campaigns>, ids: OpportunityId<ChainId>[], showTest?: boolean): {
54
- id: OpportunityId<ChainId>;
55
- all: CampaignDynamicData<ValidCampaign>[];
56
- active: CampaignDynamicData<ValidCampaign>[];
57
- inactive: CampaignDynamicData<ValidCampaign>[];
58
- }[];
@@ -1,136 +0,0 @@
1
- import { Redis } from "@/cache";
2
- import { Campaign, Int256 } from "@sdk";
3
- import moment from "moment";
4
- export const activeCampaign = (v) => v.startTimestamp < moment().unix() && v.endTimestamp > moment().unix();
5
- export const inactiveCampaign = (v) => v.startTimestamp > moment().unix() || v.endTimestamp < moment().unix();
6
- export const removeTestTokens = (v) => !["aglamerkl", "test"].includes(v.campaignParameters.symbolRewardToken?.toLowerCase());
7
- export async function getCampaignsFor(chainIds, filters = { onlyLive: false }) {
8
- const cachePrefix = filters?.onlyLive ? "LiveCampaigns" : "Campaigns";
9
- const cacheKeys = chainIds.map(chain => `${cachePrefix}_${chain}`);
10
- return (await Redis.findMany(cacheKeys)).reduce((prev, allData, index) => {
11
- if (!!allData) {
12
- const chain = chainIds[index];
13
- prev[chain] = Object.keys(allData).reduce((acc, curr) => {
14
- const [type, mainParameter] = curr.split("_");
15
- const campaignType = Number.parseInt(type);
16
- if (!filters?.types?.length || filters?.types?.includes(campaignType)) {
17
- acc[`${campaignType}_${mainParameter}`] = allData[curr];
18
- }
19
- return acc;
20
- }, {});
21
- }
22
- return prev;
23
- }, {});
24
- }
25
- /**
26
- * @returns all opportunityIds in the campaign data
27
- */
28
- export function extractIds(campaigns) {
29
- const chains = Object.keys(campaigns).map(n => Number.parseInt(n));
30
- return chains.flatMap(chainId => Object.keys(campaigns[chainId] ?? {})?.map(opportunityId => `${chainId}_${opportunityId}`));
31
- }
32
- /**
33
- * @returns the daily price of all rewards from the campaign array
34
- */
35
- export function getDailyRewards(campaigns, prices) {
36
- const rewardPrices = campaigns
37
- .map(({ campaignParameters: c, amount, endTimestamp, startTimestamp, campaignType }) => {
38
- const isSporadic = [Campaign.ERC20_SNAPSHOT, Campaign.JSON_AIRDROP].includes(campaignType);
39
- const timespan = Math.abs(endTimestamp - startTimestamp);
40
- let dayspan = isSporadic ? 1 : Math.floor(timespan / (60 * 60 * 24));
41
- if (dayspan === 0)
42
- dayspan = 1; // If distribution periode < 1 day -> avoid division by 0
43
- return [c.symbolRewardToken, Int256.from(amount, c.decimalsRewardToken).div(dayspan)];
44
- })
45
- .map(([symbol, amount]) => {
46
- return Math.max(prices?.[symbol] ?? 0, 0) * (amount?.toNumber() ?? 0);
47
- });
48
- return rewardPrices?.length > 0 ? rewardPrices.reduce((a, b) => a + b) : 0;
49
- }
50
- /**
51
- * @returns the status of an opportunity based on its campaigns
52
- */
53
- export function getStatus(campaigns) {
54
- const active = campaigns?.filter(activeCampaign);
55
- const inactive = campaigns?.filter(inactiveCampaign);
56
- if (active?.length)
57
- return "live";
58
- if (inactive?.some(v => v.startTimestamp > moment().unix()))
59
- return "soon";
60
- return "past";
61
- }
62
- /**
63
- * @returns the sum of the APRs from a campaigns array
64
- */
65
- export function getApr(campaigns) {
66
- return campaigns.reduce((res, campaign) => res + (campaign.apr ?? 0), 0);
67
- }
68
- /**
69
- * @returns the sum of the all tags
70
- */
71
- export function getTags(campaigns) {
72
- const tags = Array.from(campaigns.reduce((res, campaign) => {
73
- campaign.tags?.forEach(tag => {
74
- res.add(tag);
75
- });
76
- return res;
77
- }, new Set()));
78
- return tags.length === 0 ? undefined : tags;
79
- }
80
- /**
81
- * @returns all the reward token symbols from a compaign array
82
- */
83
- export function getRewardTokenIcons(campaigns) {
84
- const rewardTokens = new Set();
85
- campaigns.forEach(({ rewardToken }) => rewardTokens.add(rewardToken));
86
- return Array.from(rewardTokens);
87
- }
88
- /**
89
- * @returns the daily reward token symbols from a compaign array
90
- */
91
- export function getRewardTokens(campaigns) {
92
- const rewardTokens = {};
93
- campaigns.forEach(({ amount, rewardToken, campaignParameters: { symbolRewardToken: symbol }, ...c }) => {
94
- const timespan = Math.abs(c.endTimestamp - c.startTimestamp);
95
- const isWithinTimespan = moment().unix() > c.startTimestamp && moment().unix() < c.endTimestamp;
96
- const dayspan = Math.max(Math.floor(timespan / (60 * 60 * 24)), 1);
97
- const dailyAmount = isWithinTimespan ? BigInt(amount) / BigInt(dayspan) : 0n;
98
- if (!rewardTokens[symbol])
99
- rewardTokens[symbol] = { amount: dailyAmount, address: rewardToken };
100
- else
101
- rewardTokens[symbol].amount += dailyAmount;
102
- });
103
- return Object.entries(rewardTokens).map(([symbol, { amount, address }]) => ({
104
- symbol,
105
- address,
106
- amount: amount.toString(),
107
- }));
108
- }
109
- /**
110
- * @returns campaigns that match the opportunityIds
111
- */
112
- export function splitCampaigns(campaigns, ids, showTest) {
113
- if (!campaigns || !ids?.length)
114
- return [];
115
- const campaignAt = (id) => {
116
- const [chainId, type, mainParameter] = id.split("_");
117
- return (campaigns?.[chainId]?.[`${type}_${mainParameter}`] ??
118
- Object.entries(campaigns[chainId] ?? {}).find(([t_m]) => t_m?.toLowerCase() === id?.toLowerCase())?.[1]);
119
- };
120
- return ids
121
- .filter(id => campaignAt(id) !== undefined)
122
- .map(id => {
123
- let all = Object.values(campaignAt(id) ?? {});
124
- if (!showTest)
125
- all = all.filter(removeTestTokens);
126
- const active = all?.filter(activeCampaign);
127
- const inactive = all?.filter(inactiveCampaign);
128
- return {
129
- id,
130
- all,
131
- active,
132
- inactive,
133
- };
134
- })
135
- .filter(opportunity => opportunity?.all?.length);
136
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,19 +0,0 @@
1
- export type OverviewReturnType = {
2
- disputes: {
3
- [chainId: number]: {
4
- root: string;
5
- endOfDisputePeriod: number;
6
- disputeLive: boolean;
7
- treeRoot: string;
8
- lastTreeRoot: string;
9
- };
10
- };
11
- rewardTokens: {
12
- [chainId: number]: {
13
- token: string;
14
- minimumAmountPerEpoch: number;
15
- decimals: number;
16
- symbol: string;
17
- }[];
18
- };
19
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import type { ChainId } from "@sdk";
2
- export type PerChain<T> = {
3
- [Chain in ChainId]?: T;
4
- };
5
- export type Stringable = string | number | bigint | boolean | null | undefined;
@@ -1 +0,0 @@
1
- export {};