|
1 | 1 | import type { EvmProvider } from "@grants-stack-indexer/chain-providers";
|
2 |
| -import type { Address, Branded } from "@grants-stack-indexer/shared"; |
| 2 | +import type { Address } from "@grants-stack-indexer/shared"; |
3 | 3 |
|
4 | 4 | import DirectGrantsLiteStrategy from "../abis/allo-v2/v1/DirectGrantsLiteStrategy.js";
|
5 |
| -import DonationVotingMerkleDistributionDirectTransferStrategy from "../abis/allo-v2/v1/DonationVotingMerkleDistributionDirectTransferStrategy.js"; |
6 | 5 | import { StrategyTimings } from "../internal.js";
|
7 | 6 | import { getDateFromTimestamp } from "./utils.js";
|
8 | 7 |
|
9 |
| -type SanitizedStrategyId = Branded<string, "SanitizedStrategyId">; |
10 |
| -type Strategy = { |
11 |
| - id: SanitizedStrategyId; |
12 |
| - name: string | null; |
13 |
| - // TODO: check if groups are required |
14 |
| - groups: string[]; |
15 |
| -}; |
16 |
| - |
17 |
| -//TODO: refactor this into a mapping in Shared package from ID to the corresponding handler class |
18 |
| -/* |
19 |
| - * Extracts the strategy from the ID. |
20 |
| - * @param _id - The ID of the strategy. |
21 |
| - * @returns The strategy. |
22 |
| - */ |
23 |
| -export function extractStrategyFromId(_id: Address): Strategy | undefined { |
24 |
| - const id = _id.toLowerCase(); |
25 |
| - /* eslint-disable no-fallthrough */ |
26 |
| - switch (id) { |
27 |
| - // SQFSuperfluidv1 |
28 |
| - case "0xf8a14294e80ff012e54157ec9d1b2827421f1e7f6bde38c06730b1c031b3f935": |
29 |
| - return { |
30 |
| - id: id as SanitizedStrategyId, |
31 |
| - name: "allov2.SQFSuperFluidStrategy", |
32 |
| - groups: ["allov2.SQFSuperFluidStrategy"], |
33 |
| - }; |
34 |
| - |
35 |
| - // MicroGrantsv1 |
36 |
| - case "0x697f0592ebd05466d2d24454477e11d69c475d7a7c4134f15ddc1ea9811bb16f": |
37 |
| - return { |
38 |
| - id: id as SanitizedStrategyId, |
39 |
| - name: "allov2.MicroGrantsStrategy", |
40 |
| - groups: ["allov2.MicroGrantsStrategy", "allov2.MicroGrantsCommon"], |
41 |
| - }; |
42 |
| - |
43 |
| - // MicroGrantsGovv1 |
44 |
| - case "0x741ac1e2f387d83f219f6b5349d35ec34902cf94019d117335e0045d2e0ed912": |
45 |
| - return { |
46 |
| - id: id as SanitizedStrategyId, |
47 |
| - name: "allov2.MicroGrantsGovStrategy", |
48 |
| - groups: ["allov2.MicroGrantsGovStrategy", "allov2.MicroGrantsCommon"], |
49 |
| - }; |
50 |
| - |
51 |
| - // MicroGrantsHatsv1 |
52 |
| - case "0x5aa24dcfcd55a1e059a172e987b3456736b4856c71e57aaf52e9a965897318dd": |
53 |
| - return { |
54 |
| - id: id as SanitizedStrategyId, |
55 |
| - name: "allov2.MicroGrantsHatsStrategy", |
56 |
| - groups: ["allov2.MicroGrantsHatsStrategy", "allov2.MicroGrantsCommon"], |
57 |
| - }; |
58 |
| - |
59 |
| - // RFPSimpleStrategyv1.0 |
60 |
| - case "0x0d459e12d9e91d2b2a8fa12be8c7eb2b4f1c35e74573990c34b436613bc2350f": |
61 |
| - return { |
62 |
| - id: id as SanitizedStrategyId, |
63 |
| - name: "allov2.RFPSimpleStrategy", |
64 |
| - groups: ["allov2.RFPSimpleStrategy"], |
65 |
| - }; |
66 |
| - |
67 |
| - // RFPCommitteeStrategyv1.0 |
68 |
| - case "0x7d143166a83c6a8a303ae32a6ccd287e48d79818f5d15d89e185391199909803": |
69 |
| - return { |
70 |
| - id: id as SanitizedStrategyId, |
71 |
| - name: "allov2.RFPCommitteeStrategy", |
72 |
| - groups: ["allov2.RFPCommitteeStrategy"], |
73 |
| - }; |
74 |
| - |
75 |
| - // QVSimpleStrategyv1.0 |
76 |
| - case "0x22d006e191d6dc5ff1a25bb0733f47f64a9c34860b6703df88dea7cb3987b4c3": |
77 |
| - return { |
78 |
| - id: id as SanitizedStrategyId, |
79 |
| - name: "allov2.QVSimpleStrategy", |
80 |
| - groups: ["allov2.QVSimpleStrategy"], |
81 |
| - }; |
82 |
| - |
83 |
| - // DonationVotingMerkleDistributionDirectTransferStrategyv1.0 |
84 |
| - case "0x6f9291df02b2664139cec5703c124e4ebce32879c74b6297faa1468aa5ff9ebf": |
85 |
| - // DonationVotingMerkleDistributionDirectTransferStrategyv1.1 |
86 |
| - case "0x2f46bf157821dc41daa51479e94783bb0c8699eac63bf75ec450508ab03867ce": |
87 |
| - // DonationVotingMerkleDistributionDirectTransferStrategyv2.0 |
88 |
| - case "0x2f0250d534b2d59b8b5cfa5eb0d0848a59ccbf5de2eaf72d2ba4bfe73dce7c6b": |
89 |
| - // DonationVotingMerkleDistributionDirectTransferStrategyv2.1 |
90 |
| - case "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0": |
91 |
| - return { |
92 |
| - id: id as SanitizedStrategyId, |
93 |
| - name: "allov2.DonationVotingMerkleDistributionDirectTransferStrategy", |
94 |
| - groups: ["allov2.DonationVotingMerkleDistributionDirectTransferStrategy"], |
95 |
| - }; |
96 |
| - |
97 |
| - // DonationVotingMerkleDistributionVaultStrategyv1.0 |
98 |
| - case "0x7e75375f0a7cd9f7ea159c8b065976e4f764f9dcef1edf692f31dd1842f70c87": |
99 |
| - // DonationVotingMerkleDistributionVaultStrategyv1.1 |
100 |
| - case "0x093072375737c0e8872fef36808849aeba7f865e182d495f2b98308115c9ef13": |
101 |
| - return { |
102 |
| - id: id as SanitizedStrategyId, |
103 |
| - name: "allov2.DonationVotingMerkleDistributionVaultStrategy", |
104 |
| - groups: ["allov2.DonationVotingMerkleDistributionVaultStrategy"], |
105 |
| - }; |
106 |
| - |
107 |
| - // DirectGrantsSimpleStrategyv1.1 |
108 |
| - case "0x263cb916541b6fc1fb5543a244829ccdba75264b097726e6ecc3c3cfce824bf5": |
109 |
| - // DirectGrantsSimpleStrategyv2.1 |
110 |
| - case "0x53fb9d3bce0956ca2db5bb1441f5ca23050cb1973b33789e04a5978acfd9ca93": |
111 |
| - return { |
112 |
| - id: id as SanitizedStrategyId, |
113 |
| - name: "allov2.DirectGrantsSimpleStrategy", |
114 |
| - groups: ["allov2.DirectGrantsSimpleStrategy"], |
115 |
| - }; |
116 |
| - |
117 |
| - // DirectGrantsLiteStrategyv1.0 |
118 |
| - case "0x103732a8e473467a510d4128ee11065262bdd978f0d9dad89ba68f2c56127e27": |
119 |
| - return { |
120 |
| - id: id as SanitizedStrategyId, |
121 |
| - name: "allov2.DirectGrantsLiteStrategy", |
122 |
| - groups: ["allov2.DirectGrantsLiteStrategy"], |
123 |
| - }; |
124 |
| - |
125 |
| - // EasyRPGFStrategy1.0 |
126 |
| - case "0x662f5a0d3ea7e9b6ed1b351a9d96ac636a3c3ed727390aeff4ec931ae760d5ae": |
127 |
| - return { |
128 |
| - id: id as SanitizedStrategyId, |
129 |
| - name: "allov2.EasyRPGFStrategy", |
130 |
| - groups: ["allov2.EasyRPGFStrategy"], |
131 |
| - }; |
132 |
| - |
133 |
| - // DirectAllocationStrategyv1.1 |
134 |
| - case "0x4cd0051913234cdd7d165b208851240d334786d6e5afbb4d0eec203515a9c6f3": |
135 |
| - return { |
136 |
| - id: id as SanitizedStrategyId, |
137 |
| - name: "allov2.DirectAllocationStrategy", |
138 |
| - groups: ["allov2.DirectAllocationStrategy"], |
139 |
| - }; |
140 |
| - } |
141 |
| - |
142 |
| - return undefined; |
143 |
| -} |
144 |
| - |
145 |
| -//TODO: refactor this into the StrategyHandler when implemented |
146 |
| -// see if we can use a common interface or abstract class for all strategies |
147 |
| -// so we don't have to do this switch statement |
148 |
| -// most of the strategies don't need to fetch anything and just return null for all the times |
149 |
| -export const getStrategyTimings = async ( |
150 |
| - evmProvider: EvmProvider, |
151 |
| - strategy: Strategy, |
152 |
| - strategyAddress: Address, |
153 |
| -): Promise<StrategyTimings> => { |
154 |
| - switch (strategy.name) { |
155 |
| - case "allov2.DonationVotingMerkleDistributionDirectTransferStrategy": |
156 |
| - return getDonationVotingMerkleDistributionDirectTransferStrategyTimings( |
157 |
| - evmProvider, |
158 |
| - strategyAddress, |
159 |
| - ); |
160 |
| - case "allov2.DirectGrantsSimpleStrategy": |
161 |
| - case "allov2.DirectGrantsLiteStrategy": |
162 |
| - return getDirectGrantsStrategyTimings(evmProvider, strategyAddress); |
163 |
| - default: |
164 |
| - return { |
165 |
| - applicationsStartTime: null, |
166 |
| - applicationsEndTime: null, |
167 |
| - donationsStartTime: null, |
168 |
| - donationsEndTime: null, |
169 |
| - }; |
170 |
| - } |
171 |
| -}; |
172 |
| - |
173 |
| -/** |
174 |
| - * Gets the strategy data for the DonationVotingMerkleDistributionDirectTransferStrategy |
175 |
| - * @param evmProvider - The evm provider |
176 |
| - * @param strategyId - The address of the strategy |
177 |
| - * @returns The strategy data |
178 |
| - */ |
179 |
| -export const getDonationVotingMerkleDistributionDirectTransferStrategyTimings = async ( |
180 |
| - evmProvider: EvmProvider, |
181 |
| - strategyId: Address, |
182 |
| -): Promise<StrategyTimings> => { |
183 |
| - let results: [bigint, bigint, bigint, bigint] = [0n, 0n, 0n, 0n]; |
184 |
| - |
185 |
| - const contractCalls = [ |
186 |
| - { |
187 |
| - abi: DonationVotingMerkleDistributionDirectTransferStrategy, |
188 |
| - functionName: "registrationStartTime", |
189 |
| - address: strategyId, |
190 |
| - }, |
191 |
| - { |
192 |
| - abi: DonationVotingMerkleDistributionDirectTransferStrategy, |
193 |
| - functionName: "registrationEndTime", |
194 |
| - address: strategyId, |
195 |
| - }, |
196 |
| - { |
197 |
| - abi: DonationVotingMerkleDistributionDirectTransferStrategy, |
198 |
| - functionName: "allocationStartTime", |
199 |
| - address: strategyId, |
200 |
| - }, |
201 |
| - { |
202 |
| - abi: DonationVotingMerkleDistributionDirectTransferStrategy, |
203 |
| - functionName: "allocationEndTime", |
204 |
| - address: strategyId, |
205 |
| - }, |
206 |
| - ] as const; |
207 |
| - |
208 |
| - if (evmProvider.getMulticall3Address()) { |
209 |
| - results = await evmProvider.multicall({ |
210 |
| - contracts: contractCalls, |
211 |
| - allowFailure: false, |
212 |
| - }); |
213 |
| - } else { |
214 |
| - results = (await Promise.all( |
215 |
| - contractCalls.map((call) => |
216 |
| - evmProvider.readContract(call.address, call.abi, call.functionName), |
217 |
| - ), |
218 |
| - )) as [bigint, bigint, bigint, bigint]; |
219 |
| - } |
220 |
| - |
221 |
| - return { |
222 |
| - applicationsStartTime: getDateFromTimestamp(results[0]), |
223 |
| - applicationsEndTime: getDateFromTimestamp(results[1]), |
224 |
| - donationsStartTime: getDateFromTimestamp(results[2]), |
225 |
| - donationsEndTime: getDateFromTimestamp(results[3]), |
226 |
| - }; |
227 |
| -}; |
228 |
| - |
| 8 | +//TODO: move this to the DirectGrantsStrategyHandler when implemented |
229 | 9 | /**
|
230 | 10 | * Gets the strategy data for the DirectGrantsStrategy
|
231 | 11 | * @param evmProvider - The evm provider
|
|
0 commit comments