forked from snapshot-labs/snapshot-strategies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
54 lines (51 loc) · 1.09 KB
/
utils.ts
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
import _strategies from './strategies';
import snapshot from '@snapshot-labs/snapshot.js';
export async function getScoresDirect(
space: string,
strategies: any[],
network: string,
provider,
addresses: string[],
snapshot: number | string = 'latest'
) {
try {
return await Promise.all(
strategies.map((strategy) =>
(snapshot !== 'latest' && strategy.params?.start > snapshot) ||
(strategy.params?.end &&
(snapshot === 'latest' || snapshot > strategy.params?.end)) ||
addresses.length === 0
? {}
: _strategies[strategy.name].strategy(
space,
network,
provider,
addresses,
strategy.params,
snapshot
)
)
);
} catch (e) {
return Promise.reject(e);
}
}
export const {
multicall,
Multicaller,
subgraphRequest,
ipfsGet,
call,
getBlockNumber,
getProvider
} = snapshot.utils;
export default {
getScoresDirect,
multicall,
Multicaller,
subgraphRequest,
ipfsGet,
call,
getBlockNumber,
getProvider
};