-
Notifications
You must be signed in to change notification settings - Fork 809
/
Copy pathindex.ts
68 lines (62 loc) · 1.85 KB
/
index.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { getDelegations } from '../../utils/delegation';
import { getScoresDirect, getSnapshots } from '../../utils';
export const author = 'bonustrack';
export const version = '0.1.0';
export const dependOnOtherAddress = true;
export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
) {
const invalidStrategies = [
'{"name":"erc20-balance-of","params":{"symbol":"HOP","address":"0xed8Bdb5895B8B7f9Fdb3C087628FD8410E853D48","decimals":18}}' //https://snapshot.org/#/hop.eth/proposal/0x603f0f6e54c7be8d5db7e16ae7145e6df4b439b8aac49654cdfd6b0c03eb6492
];
if (
options.strategies.some((s) =>
invalidStrategies.includes(JSON.stringify(s))
)
)
return {};
const delegationSpace = options.delegationSpace || space;
const delegationNetwork = options.delegationNetwork || network;
let delegationSnapshot = snapshot;
if (delegationNetwork !== network) {
const snapshots = await getSnapshots(network, snapshot, provider, [
delegationNetwork
]);
delegationSnapshot = snapshots[delegationNetwork];
}
const delegations = await getDelegations(
delegationSpace,
delegationNetwork,
addresses,
delegationSnapshot
);
if (Object.keys(delegations).length === 0) return {};
const scores = (
await getScoresDirect(
space,
options.strategies,
network,
provider,
Object.values(delegations).reduce((a: string[], b: string[]) =>
a.concat(b)
),
snapshot
)
).filter((score) => Object.keys(score).length !== 0);
return Object.fromEntries(
addresses.map((address) => {
const addressScore = delegations[address]
? delegations[address].reduce(
(a, b) => a + scores.reduce((x, y) => (y[b] ? x + y[b] : x), 0),
0
)
: 0;
return [address, addressScore];
})
);
}