Skip to content

Commit

Permalink
Add in gov bravo versions of proposal and vote receipt lens functions. (
Browse files Browse the repository at this point in the history
#109)

* Add in gov bravo versions or proposal and vote receition lens functions.

* Begin trying out an interface to allow me to call the methods I need without import GovBravo.

* try to fix solidity issues

* Remove arrays

* Update network configs

Co-authored-by: Geoffrey Hayes <[email protected]>
Co-authored-by: Jared Flatow <[email protected]>
  • Loading branch information
3 people authored Apr 12, 2021
1 parent 1243a5e commit b9b1403
Show file tree
Hide file tree
Showing 7 changed files with 99,781 additions and 101,605 deletions.
107 changes: 107 additions & 0 deletions contracts/Lens/CompoundLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ interface ComptrollerLensInterface {
function compAccrued(address) external view returns (uint);
}

interface GovernorBravoInterface {
struct Receipt {
bool hasVoted;
uint8 support;
uint96 votes;
}
struct Proposal {
uint id;
address proposer;
uint eta;
uint startBlock;
uint endBlock;
uint forVotes;
uint againstVotes;
uint abstainVotes;
bool canceled;
bool executed;
}
function getActions(uint proposalId) external view returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas);
function proposals(uint proposalId) external view returns (Proposal memory);
function getReceipt(uint proposalId, address voter) external view returns (Receipt memory);
}

contract CompoundLens {
struct CTokenMetadata {
address cToken;
Expand Down Expand Up @@ -186,6 +209,28 @@ contract CompoundLens {
return res;
}

struct GovBravoReceipt {
uint proposalId;
bool hasVoted;
uint8 support;
uint96 votes;
}

function getGovBravoReceipts(GovernorBravoInterface governor, address voter, uint[] memory proposalIds) public view returns (GovBravoReceipt[] memory) {
uint proposalCount = proposalIds.length;
GovBravoReceipt[] memory res = new GovBravoReceipt[](proposalCount);
for (uint i = 0; i < proposalCount; i++) {
GovernorBravoInterface.Receipt memory receipt = governor.getReceipt(proposalIds[i], voter);
res[i] = GovBravoReceipt({
proposalId: proposalIds[i],
hasVoted: receipt.hasVoted,
support: receipt.support,
votes: receipt.votes
});
}
return res;
}

struct GovProposal {
uint proposalId;
address proposer;
Expand Down Expand Up @@ -254,6 +299,68 @@ contract CompoundLens {
return res;
}

struct GovBravoProposal {
uint proposalId;
address proposer;
uint eta;
address[] targets;
uint[] values;
string[] signatures;
bytes[] calldatas;
uint startBlock;
uint endBlock;
uint forVotes;
uint againstVotes;
uint abstainVotes;
bool canceled;
bool executed;
}

function setBravoProposal(GovBravoProposal memory res, GovernorBravoInterface governor, uint proposalId) internal view {
GovernorBravoInterface.Proposal memory p = governor.proposals(proposalId);

res.proposalId = proposalId;
res.proposer = p.proposer;
res.eta = p.eta;
res.startBlock = p.startBlock;
res.endBlock = p.endBlock;
res.forVotes = p.forVotes;
res.againstVotes = p.againstVotes;
res.abstainVotes = p.abstainVotes;
res.canceled = p.canceled;
res.executed = p.executed;
}

function getGovBravoProposals(GovernorBravoInterface governor, uint[] calldata proposalIds) external view returns (GovBravoProposal[] memory) {
GovBravoProposal[] memory res = new GovBravoProposal[](proposalIds.length);
for (uint i = 0; i < proposalIds.length; i++) {
(
address[] memory targets,
uint[] memory values,
string[] memory signatures,
bytes[] memory calldatas
) = governor.getActions(proposalIds[i]);
res[i] = GovBravoProposal({
proposalId: 0,
proposer: address(0),
eta: 0,
targets: targets,
values: values,
signatures: signatures,
calldatas: calldatas,
startBlock: 0,
endBlock: 0,
forVotes: 0,
againstVotes: 0,
abstainVotes: 0,
canceled: false,
executed: false
});
setBravoProposal(res[i], governor, proposalIds[i]);
}
return res;
}

struct CompBalanceMetadata {
uint balance;
uint votes;
Expand Down
Loading

0 comments on commit b9b1403

Please sign in to comment.