Skip to content

Commit

Permalink
rebranded comp
Browse files Browse the repository at this point in the history
  • Loading branch information
rubydog committed Mar 18, 2021
1 parent 6f37baf commit c0bc010
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
24 changes: 12 additions & 12 deletions contracts/GovernerAlpha.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import "hardhat/console.sol";

contract GovernorAlpha {
/// @notice The name of this contract
string public constant name = "Compound Governor Alpha";
string public constant name = "BTRUST Governor Alpha";

/// @notice The number of votes in support of a proposal required in order for a quorum to be reached and for a vote to succeed
function quorumVotes() public pure returns (uint) { return 400000e18; } // 400,000 = 4% of Comp
function quorumVotes() public pure returns (uint) { return 400000e18; } // 400,000 = 4% of BTRUST

/// @notice The number of votes required in order for a voter to become a proposer
function proposalThreshold() public pure returns (uint) { return 100000e18; } // 100,000 = 1% of Comp
function proposalThreshold() public pure returns (uint) { return 100000e18; } // 100,000 = 1% of BTRUST

/// @notice The maximum number of actions that can be included in a proposal
function proposalMaxOperations() public pure returns (uint) { return 10; } // 10 actions
Expand All @@ -22,11 +22,11 @@ contract GovernorAlpha {
/// @notice The duration of voting on a proposal, in blocks
function votingPeriod() public pure returns (uint) { return 17280; } // ~3 days in blocks (assuming 15s blocks)

/// @notice The address of the Compound Protocol Timelock
/// @notice The address of the BTRUST Protocol Timelock
TimelockInterface public timelock;

/// @notice The address of the Compound governance token
CompInterface public comp;
/// @notice The address of the BTRUST governance token
BTRUSTInterface public BTRUST;

/// @notice The address of the Governor Guardian
address public guardian;
Expand Down Expand Up @@ -129,14 +129,14 @@ contract GovernorAlpha {
/// @notice An event emitted when a proposal has been executed in the Timelock
event ProposalExecuted(uint id);

constructor(address timelock_, address comp_, address guardian_) public {
constructor(address timelock_, address BTRUST_, address guardian_) public {
timelock = TimelockInterface(timelock_);
comp = CompInterface(comp_);
BTRUST = BTRUSTInterface(BTRUST_);
guardian = guardian_;
}

function propose(address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas, string memory description) public returns (uint) {
require(comp.getPriorVotes(msg.sender, sub256(block.number, 1)) > proposalThreshold(), "GovernorAlpha::propose: proposer votes below proposal threshold");
require(BTRUST.getPriorVotes(msg.sender, sub256(block.number, 1)) > proposalThreshold(), "GovernorAlpha::propose: proposer votes below proposal threshold");
require(targets.length == values.length && targets.length == signatures.length && targets.length == calldatas.length, "GovernorAlpha::propose: proposal function information arity mismatch");
require(targets.length != 0, "GovernorAlpha::propose: must provide actions");
require(targets.length <= proposalMaxOperations(), "GovernorAlpha::propose: too many actions");
Expand Down Expand Up @@ -206,7 +206,7 @@ contract GovernorAlpha {
require(state != ProposalState.Executed, "GovernorAlpha::cancel: cannot cancel executed proposal");

Proposal storage proposal = proposals[proposalId];
require(msg.sender == guardian || comp.getPriorVotes(proposal.proposer, sub256(block.number, 1)) < proposalThreshold(), "GovernorAlpha::cancel: proposer above threshold");
require(msg.sender == guardian || BTRUST.getPriorVotes(proposal.proposer, sub256(block.number, 1)) < proposalThreshold(), "GovernorAlpha::cancel: proposer above threshold");

proposal.canceled = true;
for (uint i = 0; i < proposal.targets.length; i++) {
Expand Down Expand Up @@ -265,7 +265,7 @@ contract GovernorAlpha {
Proposal storage proposal = proposals[proposalId];
Receipt storage receipt = proposal.receipts[voter];
require(receipt.hasVoted == false, "GovernorAlpha::_castVote: voter already voted");
uint96 votes = comp.getPriorVotes(voter, proposal.startBlock);
uint96 votes = BTRUST.getPriorVotes(voter, proposal.startBlock);

if (support) {
proposal.forVotes = add256(proposal.forVotes, votes);
Expand Down Expand Up @@ -328,6 +328,6 @@ interface TimelockInterface {
function executeTransaction(address target, uint value, string calldata signature, bytes calldata data, uint eta) external payable returns (bytes memory);
}

interface CompInterface {
interface BTRUSTInterface {
function getPriorVotes(address account, uint blockNumber) external view returns (uint96);
}
40 changes: 20 additions & 20 deletions test/GovernerAlpha.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ const {
const BigNumber = require('bignumber.js');
const chalk = require('chalk');

async function enfranchise(comp, actor, amount) {
await comp.transfer(actor, etherMantissa(amount));
await comp.delegate(actor, { from: actor });
async function enfranchise(btrust, actor, amount) {
await btrust.transfer(actor, etherMantissa(amount));
await btrust.delegate(actor, { from: actor });
}

describe("governorAlpha#castVote/2", () => {
let comp, gov, root, a1, accounts;
let btrust, gov, root, a1, accounts;
let targets, values, signatures, callDatas, proposalId;

before(async () => {
[root, a1, ...accounts] = await web3.eth.getAccounts();
comp = await BTRUST.new(root);
gov = await GovernorAlpha.new(address(0), comp.address, root)
btrust = await BTRUST.new(root);
gov = await GovernorAlpha.new(address(0), btrust.address, root)

targets = [a1];
values = ["0"];
signatures = ["getBalanceOf(address)"];
callDatas = [encodeParameters(['address'], [a1])];
await comp.delegate(root);
await btrust.delegate(root);
await gov.propose(targets, values, signatures, callDatas, "do nothing");
proposalId = await gov.latestProposalIds(root);
// proposalId = proposalId.toString();
Expand Down Expand Up @@ -74,7 +74,7 @@ const {

it("and we add that ForVotes", async () => {
actor = accounts[1];
await enfranchise(comp, actor, 400001);
await enfranchise(btrust, actor, 400001);

await gov.propose(targets, values, signatures, callDatas, "do nothing", { from: actor });
proposalId = await gov.latestProposalIds(actor);
Expand All @@ -89,7 +89,7 @@ const {

it("or AgainstVotes corresponding to the caller's support flag.", async () => {
actor = accounts[3];
await enfranchise(comp, actor, 400001);
await enfranchise(btrust, actor, 400001);

await gov.propose(targets, values, signatures, callDatas, "do nothing", { from: actor });
proposalId = await gov.latestProposalIds(actor);
Expand All @@ -105,7 +105,7 @@ const {

describe('castVoteBySig', () => {
const Domain = (gov) => ({
name: 'Compound Governor Alpha',
name: 'BTRUST Governor Alpha',
chainId: 1, // await web3.eth.net.getId(); See: https://github.com/trufflesuite/ganache-core/issues/515
verifyingContract: gov.address
});
Expand All @@ -125,7 +125,7 @@ const {
console.log(signatory.address)
console.log(a1.privateKey)

await enfranchise(comp, signatory.address, 400001);
await enfranchise(btrust, signatory.address, 400001);
await gov.propose(targets, values, signatures, callDatas, "do nothing", { from: signatory.address });
proposalId = await gov.latestProposalIds(signatory.address);;

Expand All @@ -144,8 +144,8 @@ const {
it.skip("receipt uses one load", async () => {
let actor = accounts[2];
let actor2 = accounts[3];
await enfranchise(comp, actor, 400001);
await enfranchise(comp, actor2, 400001);
await enfranchise(btrust, actor, 400001);
await enfranchise(btrust, actor2, 400001);
await gov.propose(targets, values, signatures, callDatas, "do nothing", { from: actor });
proposalId = await gov.latestProposalIds(actor);;

Expand Down Expand Up @@ -207,8 +207,8 @@ const {

before(async () => {
[root, acct, ...accounts] = await web3.eth.getAccounts();
comp = await BTRUST.new(root);
gov = await GovernorAlpha.new(address(0), comp.address, address(0))
btrust = await BTRUST.new(root);
gov = await GovernorAlpha.new(address(0), btrust.address, address(0))
});

let trivialProposal, targets, values, signatures, callDatas;
Expand All @@ -218,7 +218,7 @@ const {
values = ["0"];
signatures = ["getBalanceOf(address)"];
callDatas = [encodeParameters(['address'], [acct])];
await comp.delegate(root);
await btrust.delegate(root);
await gov.propose(targets, values, signatures, callDatas, "do nothing");
proposalBlock = +(await web3.eth.getBlockNumber());
proposalId = await gov.latestProposalIds(root);
Expand Down Expand Up @@ -316,8 +316,8 @@ const {
});

it.skip("This function returns the id of the newly created proposal. # proposalId(n) = succ(proposalId(n-1))", async () => {
await comp.transfer(accounts[2], etherMantissa(400001));
await comp.delegate(accounts[2], { from: accounts[2] });
await btrust.transfer(accounts[2], etherMantissa(400001));
await btrust.delegate(accounts[2], { from: accounts[2] });

await mineBlock();
let nextProposalId = await gov.propose(targets, values, signatures, callDatas, "yoot", { from: accounts[2] });
Expand All @@ -326,8 +326,8 @@ const {
});

it.skip("emits log with id and description", async () => {
await send(comp, 'transfer', [accounts[3], etherMantissa(400001)]);
await send(comp, 'delegate', [accounts[3]], { from: accounts[3] });
await send(btrust, 'transfer', [accounts[3], etherMantissa(400001)]);
await send(btrust, 'delegate', [accounts[3]], { from: accounts[3] });
await mineBlock();
let nextProposalId = await gov.methods['propose'](targets, values, signatures, callDatas, "yoot").call({ from: accounts[3] });

Expand Down

0 comments on commit c0bc010

Please sign in to comment.