tornado-aggregator/contracts/GovernanceAggregator.sol

78 lines
2.1 KiB
Solidity
Raw Permalink Normal View History

2020-10-07 15:05:34 +02:00
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.12;
pragma experimental ABIEncoderV2;
import "tornado-governance/contracts/Governance.sol";
contract GovernanceAggregator {
struct Proposal {
address proposer;
address target;
uint256 startTime;
uint256 endTime;
uint256 forVotes;
uint256 againstVotes;
bool executed;
bool extended;
Governance.ProposalState state;
}
2020-10-21 08:31:09 +02:00
function getAllProposals(Governance governance) public view returns (Proposal[] memory proposals) {
proposals = new Proposal[](governance.proposalCount());
2020-10-07 15:05:34 +02:00
2020-10-21 08:31:09 +02:00
for (uint256 i = 0; i < proposals.length; i++) {
2020-10-07 15:05:34 +02:00
(
address proposer,
address target,
uint256 startTime,
uint256 endTime,
uint256 forVotes,
uint256 againstVotes,
bool executed,
bool extended
2020-10-21 08:31:09 +02:00
) = governance.proposals(i + 1);
2020-10-07 15:05:34 +02:00
2020-10-21 08:31:09 +02:00
proposals[i] = Proposal({
2020-10-07 15:05:34 +02:00
proposer: proposer,
target: target,
startTime: startTime,
endTime: endTime,
forVotes: forVotes,
againstVotes: againstVotes,
executed: executed,
extended: extended,
2020-10-21 08:31:09 +02:00
state: governance.state(i + 1)
2020-10-07 15:05:34 +02:00
});
}
}
2020-10-08 11:06:43 +02:00
function getGovernanceBalances(Governance governance, address[] calldata accs) public view returns (uint256[] memory amounts) {
2020-10-07 15:05:34 +02:00
amounts = new uint256[](accs.length);
for (uint256 i = 0; i < accs.length; i++) {
amounts[i] = governance.lockedBalance(accs[i]);
2020-10-07 15:05:34 +02:00
}
}
function getUserData(Governance governance, address account)
public
view
returns (
uint256 balance,
uint256 latestProposalId,
2020-10-30 04:58:42 +01:00
uint256 latestProposalIdState,
uint256 timelock,
address delegatee
)
{
// Core core = Core(address(governance));
balance = governance.lockedBalance(account);
latestProposalId = governance.latestProposalIds(account);
2020-10-30 04:58:42 +01:00
if (latestProposalId != 0) {
latestProposalIdState = uint256(governance.state(latestProposalId));
2020-10-30 04:56:10 +01:00
}
timelock = governance.canWithdrawAfter(account);
delegatee = governance.delegatedTo(account);
}
2020-10-07 15:05:34 +02:00
}