-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPartyHelpers.sol
126 lines (111 loc) · 3.82 KB
/
PartyHelpers.sol
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
116
117
118
119
120
121
122
123
124
125
126
// SPDX-License-Identifier: Beta Software
pragma solidity ^0.8;
import "../party/Party.sol";
/// @notice Helpers for getting data from contract off-chain.
contract PartyHelpers {
enum CrowdfundType {
Bid,
Buy,
CollectionBuy
}
struct MemberAndDelegate {
address member;
address delegate;
}
struct MemberAndVotingPower {
address member;
uint96 votingPower;
}
struct NftInfo {
uint256 tokenId;
address owner;
uint256 intrinsicVotingPower;
}
////////////////////////////
// Crowdfund helpers //
////////////////////////////
function getCrowdfundType(address globals, address crowdfund)
external
view
returns (CrowdfundType)
{
IGlobals g = IGlobals(globals);
Implementation cf = Implementation(crowdfund);
address impl = cf.IMPL();
if (impl == g.getImplementation(LibGlobals.GLOBAL_AUCTION_CF_IMPL).IMPL()) {
return CrowdfundType.Bid;
} else if (impl == g.getImplementation(LibGlobals.GLOBAL_BUY_CF_IMPL).IMPL()) {
return CrowdfundType.Buy;
} else if (impl == g.getImplementation(LibGlobals.GLOBAL_COLLECTION_BUY_CF_IMPL).IMPL()) {
return CrowdfundType.CollectionBuy;
}
revert("PartyHelpers::Unknown CrowdfundType");
}
/////////////////////////////
// PartyGovernance helpers //
/////////////////////////////
/// @notice Get the current delegate for each member in `members`
function getCurrentDelegates(address party, address[] calldata members)
external
view
returns (MemberAndDelegate[] memory membersAndDelegates)
{
Party p = Party(payable(party));
membersAndDelegates = new MemberAndDelegate[](members.length);
for (uint256 i = 0; i < members.length; i++) {
membersAndDelegates[i] = MemberAndDelegate({
member: members[i],
delegate: p.delegationsByVoter(members[i])
});
}
}
/// @notice Get the total voting power of each voter in `voters` at a timestamp.
function getVotingPowersAt(
address party,
address[] calldata voters,
uint40 timestamp,
uint256[] calldata indexes
)
external
view
returns (MemberAndVotingPower[] memory memberAndVotingPower)
{
Party p = Party(payable(party));
memberAndVotingPower = new MemberAndVotingPower[](voters.length);
for (uint256 i = 0; i < voters.length; i++) {
memberAndVotingPower[i] = MemberAndVotingPower({
member: voters[i],
votingPower: p.getVotingPowerAt(voters[i], timestamp, indexes[i])
});
}
}
////////////////////////////////
// PartyGovernanceNFT helpers //
////////////////////////////////
/// @notice Get the owner and intrinsic voting power of each governance nft in a range
function getNftInfos(address party, uint256 startTokenId, uint256 endTokenId)
external
view
returns (NftInfo[] memory nftInfos)
{
Party p = Party(payable(party));
uint256 count = endTokenId - startTokenId + 1;
{
uint256 tokenCount = p.tokenCount();
if (count > tokenCount) {
count = tokenCount + 1 - startTokenId;
}
}
nftInfos = new NftInfo[](count);
for (uint256 i = 0; i < count; i++) {
uint256 currIndex = startTokenId + i;
address owner = p.ownerOf(currIndex);
uint256 intrinsicVotingPower = p.votingPowerByTokenId(currIndex);
nftInfos[i] = NftInfo({
intrinsicVotingPower: intrinsicVotingPower,
owner: owner,
tokenId: currIndex
});
}
}
}