Skip to content

Commit

Permalink
Merge pull request justlend#13 from justlend/feature/governance-bravo
Browse files Browse the repository at this point in the history
Support GovernorBravo
  • Loading branch information
supersmartguy01 authored Nov 1, 2022
2 parents 1fadc93 + c9c26a8 commit 3b97768
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 17 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ We detail a few of the core contracts in the Justlend protocol.
</dl>

<dl>
<dt>GovernorAlpha</dt>
<dd>The administrator of the Justlend timelock contract. Holders of JST token may create and vote on proposals which will be queued into the Justlend timelock and then have effects on Justlend jToken and Comptroller contracts. This contract may be replaced in the future with a beta version.</dd>
<dt>GovernorAlpha (Deprecated)</dt>
<dd>Old governance contract. The administrator of the Justlend timelock contract. Holders of JST token may create and vote on proposals which will be queued into the Justlend timelock and then have effects on Justlend jToken and Comptroller contracts. </dd>
</dl>

<dl>
<dt>GovernorBravo </dt>
<dd>The current used governance contract. The administrator of the Justlend timelock contract. Holders of JST token may create and vote on proposals which will be queued into the Justlend timelock and then have effects on Justlend jToken and Comptroller contracts. </dd>
</dl>

<dl>
Expand Down
22 changes: 12 additions & 10 deletions contracts/Governance/Bravo/GovernorBravoDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE
* @notice Internal function that caries out voting logic
* @param voter The voter that is casting their vote
* @param proposalId The id of the proposal to vote on
* @param votes The number of Voter's total votes to proposalId, should gt has voted
* @param support The support value for the vote. 0=against, 1=for, 2=abstain
* @return The number of votes cast
* @return The number of total votes cast.
*/
function castVoteInternal(address voter, uint proposalId, uint votes, uint8 support) internal returns (uint96) {
require(state(proposalId) == ProposalState.Active, "GovernorBravo::castVoteInternal: voting is closed");
Expand All @@ -272,26 +273,27 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE
Receipt storage receipt = proposal.receipts[voter];
require(receipt.hasVoted == false || receipt.support == support, "GovernorBravo::castVoteInternal: wrong voter status");
// uint96 votes = wjst.getPriorVotes(voter, proposal.startBlock);
require(votes <= wjst.getPriorVotes(voter, proposal.startBlock), "GovernorBravo::castVoteInternal: short of vote power");
require(votes >= receipt.votes, "GovernorBravo::castVoteInternal: votes should greater than or equal to the number has voted");
uint256 votesAdded = votes - receipt.votes;
require(votesAdded <= wjst.getPriorVotes(voter, proposal.startBlock), "GovernorBravo::castVoteInternal: short of vote power");

if (support == 0) {
proposal.againstVotes = add256(proposal.againstVotes, votes);
proposal.againstVotes = add256(proposal.againstVotes, votesAdded);
} else if (support == 1) {
proposal.forVotes = add256(proposal.forVotes, votes);
proposal.forVotes = add256(proposal.forVotes, votesAdded);
} else if (support == 2) {
proposal.abstainVotes = add256(proposal.abstainVotes, votes);
proposal.abstainVotes = add256(proposal.abstainVotes, votesAdded);
}

require(wjst.voteFresh(voter, proposalId, support, votes), "wjst vote exception");
require(wjst.voteFresh(voter, proposalId, support, votesAdded), "wjst vote exception");
receipt.hasVoted = true;
receipt.support = support;
uint _votes = add256(receipt.votes, votes);
receipt.votes = uint96(_votes);
receipt.votes = uint96(votes);

//TODO ProposalSnapshot abstainVotes
// emit ProposalSnapshot(proposalId, proposal.forVotes, proposal.againstVotes);
emit ProposalSnapshotBravo(proposalId, proposal.forVotes, proposal.againstVotes, proposal.abstainVotes);
return uint96(_votes);
return uint96(votes);
}

/**
Expand Down Expand Up @@ -437,4 +439,4 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE
assembly {chainId := chainid()}
return uint(uint8(chainId));
}
}
}
2 changes: 1 addition & 1 deletion contracts/Governance/Bravo/GovernorBravoDelegator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ contract GovernorBravoDelegator is GovernorBravoDelegatorStorage, GovernorBravoE
default {return (free_mem_ptr, returndatasize)}
}
}
}
}
2 changes: 1 addition & 1 deletion contracts/Governance/Bravo/GovernorBravoInterfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,4 @@ interface WjstInterface {
interface GovernorAlpha {
/// @notice The total number of proposals
function proposalCount() external returns (uint);
}
}
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Comptroller [TB23wYojvAsSx6gR8ebHiBqwSeABiBMPAr](https://tronscan.org/#/contract

GovernorBravoDelegator [TEqiF5JbhDPD77yjEfnEMncGRZNDt2uogD](https://tronscan.org/#/contract/TEqiF5JbhDPD77yjEfnEMncGRZNDt2uogD)

GovernorBravoDelegate [TCiQTkxhzwSeXhRsNdHCvrxHRAvpjQn5Dt](https://tronscan.io/#/contract/TCiQTkxhzwSeXhRsNdHCvrxHRAvpjQn5Dt/code)

WJST [TXk9LnTnLN7oH96H3sKxJayMxLxR9M4ZD6](https://tronscan.org/#/contract/TXk9LnTnLN7oH96H3sKxJayMxLxR9M4ZD6)

Timelock [TRWNvb15NmfNKNLhQpxefFz7cNjrYjEw7x](https://tronscan.org/#/contract/TRWNvb15NmfNKNLhQpxefFz7cNjrYjEw7x)
Expand Down
24 changes: 24 additions & 0 deletions migrations/9_deploy_governance_bravo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const GovernorBravoDelegate = artifacts.require("./GovernorBravoDelegate.sol");
const GovernorBravoDelegator = artifacts.require("./GovernorBravoDelegator.sol");

const TIMELOCK_ADDRESS = process.env.TIMELOCK_ADDRESS;
const WJST_ADDRESS = process.env.WJST_ADDRESS;
const VOTING_PERIOD = process.env.VOTING_PERIOD;
const VOTING_DELAY = process.env.VOTING_DELAY;
const PROPOSAL_THRESHOLD = process.env.PROPOSAL_THRESHOLD;
const ADMIN_ADDRESS = process.env.ADMIN_ADDRESS;

module.exports = async function(deployer) {
await deployer.deploy(GovernorBravoDelegate);
await GovernorBravoDelegate.deployed();
await deployer.deploy(
GovernorBravoDelegator,
TIMELOCK_ADDRESS,
WJST_ADDRESS,
ADMIN_ADDRESS,
GovernorBravoDelegate.address,
VOTING_PERIOD,
VOTING_DELAY,
PROPOSAL_THRESHOLD
);
}
10 changes: 9 additions & 1 deletion sample-env
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
PRIVATE_KEY_NILE=
RESERVER_ADMIN=
ADMIN=
ADMIN=

#For Governance Bravo deployment
TIMELOCK_ADDRESS=
WJST_ADDRESS=
ADMIN_ADDRESS=
VOTING_PERIOD=28800
VOTING_DELAY=1
PROPOSAL_THRESHOLD=100000000000000000000000000
5 changes: 3 additions & 2 deletions tronbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Then, run the migration with:
},
compilers: {
solc: {
version: '0.5.12',
version: '0.5.16',
}
}
},
Expand All @@ -55,6 +55,7 @@ Then, run the migration with:
optimizer: {
enabled: true,
runs: 10000
}
},
evmVersion: "istanbul"
},
}

0 comments on commit 3b97768

Please sign in to comment.