-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathutils.ts
More file actions
115 lines (107 loc) · 4.35 KB
/
utils.ts
File metadata and controls
115 lines (107 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { OrderByRounds, RoundCategory, RoundPayoutType, v2Project } from ".";
/**
* Merges canonical and linked projects into a single array of projects
* where linked projects are linked to their canonical project by chian ID.
*
* @param projects - Array of v2 projects
*
* @returns - Array of merged v2 projects
*/
export const mergeCanonicalAndLinkedProjects = (
projects: v2Project[],
): v2Project[] => {
const canonicalProjects = projects.filter(
(project) => project.projectType === "canonical",
);
const linkedProjects = projects.filter(
(project) => project.projectType === "linked",
);
const allProjects: Record<string, v2Project> = {};
for (const project of canonicalProjects) {
allProjects[project.id] = project;
}
for (const project of linkedProjects) {
if (Object.prototype.hasOwnProperty.call(allProjects, project.id)) {
if (!allProjects[project.id].linkedChains) {
allProjects[project.id].linkedChains = [];
}
allProjects[project.id].linkedChains?.push(project.chainId);
}
}
return Object.values(allProjects);
};
export const strategyNameToCategory = (
name: RoundPayoutType | string,
): RoundCategory => {
switch (name) {
case "allov1.Direct":
case "allov2.DirectGrantsSimpleStrategy":
case "allov2.DirectGrantsLiteStrategy":
return RoundCategory.Direct;
case "allov2.EasyRetroFundingStrategy":
return RoundCategory.Retrofunding;
case "allov1.QF":
case "allov2.DonationVotingMerkleDistributionDirectTransferStrategy":
return RoundCategory.QuadraticFunding;
default:
throw new Error(`Unknown round strategy: ${name}`);
}
};
export const orderByMapping: Record<
OrderByRounds,
{ [key: string]: "ASC" | "DESC" }
> = {
NATURAL: {},
ID_ASC: { id: "ASC" },
ID_DESC: { id: "DESC" },
CHAIN_ID_ASC: { chainId: "ASC" },
CHAIN_ID_DESC: { chainId: "DESC" },
TAGS_ASC: { tags: "ASC" },
TAGS_DESC: { tags: "DESC" },
MATCH_AMOUNT_ASC: { matchAmount: "ASC" },
MATCH_AMOUNT_DESC: { matchAmount: "DESC" },
MATCH_TOKEN_ADDRESS_ASC: { matchTokenAddress: "ASC" },
MATCH_TOKEN_ADDRESS_DESC: { matchTokenAddress: "DESC" },
MATCH_AMOUNT_IN_USD_ASC: { matchAmountInUsd: "ASC" },
MATCH_AMOUNT_IN_USD_DESC: { matchAmountInUsd: "DESC" },
APPLICATION_METADATA_CID_ASC: { applicationMetadataCid: "ASC" },
APPLICATION_METADATA_CID_DESC: { applicationMetadataCid: "DESC" },
APPLICATION_METADATA_ASC: { applicationMetadata: "ASC" },
APPLICATION_METADATA_DESC: { applicationMetadata: "DESC" },
ROUND_METADATA_CID_ASC: { roundMetadataCid: "ASC" },
ROUND_METADATA_CID_DESC: { roundMetadataCid: "DESC" },
ROUND_METADATA_ASC: { roundMetadata: "ASC" },
ROUND_METADATA_DESC: { roundMetadata: "DESC" },
APPLICATIONS_START_TIME_ASC: { applicationsStartTime: "ASC" },
APPLICATIONS_START_TIME_DESC: { applicationsStartTime: "DESC" },
APPLICATIONS_END_TIME_ASC: { applicationsEndTime: "ASC" },
APPLICATIONS_END_TIME_DESC: { applicationsEndTime: "DESC" },
DONATIONS_START_TIME_ASC: { donationsStartTime: "ASC" },
DONATIONS_START_TIME_DESC: { donationsStartTime: "DESC" },
DONATIONS_END_TIME_ASC: { donationsEndTime: "ASC" },
DONATIONS_END_TIME_DESC: { donationsEndTime: "DESC" },
CREATED_AT_BLOCK_ASC: { createdAtBlock: "ASC" },
CREATED_AT_BLOCK_DESC: { createdAtBlock: "DESC" },
UPDATED_AT_BLOCK_ASC: { updatedAtBlock: "ASC" },
UPDATED_AT_BLOCK_DESC: { updatedAtBlock: "DESC" },
MANAGER_ROLE_ASC: { managerRole: "ASC" },
MANAGER_ROLE_DESC: { managerRole: "DESC" },
ADMIN_ROLE_ASC: { adminRole: "ASC" },
ADMIN_ROLE_DESC: { adminRole: "DESC" },
STRATEGY_ADDRESS_ASC: { strategyAddress: "ASC" },
STRATEGY_ADDRESS_DESC: { strategyAddress: "DESC" },
STRATEGY_ID_ASC: { strategyId: "ASC" },
STRATEGY_ID_DESC: { strategyId: "DESC" },
STRATEGY_NAME_ASC: { strategyName: "ASC" },
STRATEGY_NAME_DESC: { strategyName: "DESC" },
PROJECT_ID_ASC: { projectId: "ASC" },
PROJECT_ID_DESC: { projectId: "DESC" },
TOTAL_AMOUNT_DONATED_IN_USD_ASC: { totalAmountDonatedInUsd: "ASC" },
TOTAL_AMOUNT_DONATED_IN_USD_DESC: { totalAmountDonatedInUsd: "DESC" },
TOTAL_DONATIONS_COUNT_ASC: { totalDonationsCount: "ASC" },
TOTAL_DONATIONS_COUNT_DESC: { totalDonationsCount: "DESC" },
UNIQUE_DONORS_COUNT_ASC: { uniqueDonorsCount: "ASC" },
UNIQUE_DONORS_COUNT_DESC: { uniqueDonorsCount: "DESC" },
PRIMARY_KEY_ASC: { id: "ASC" },
PRIMARY_KEY_DESC: { id: "DESC" },
};