Skip to content

Commit

Permalink
Appease scopelint
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlaprade committed Dec 15, 2022
1 parent 2787229 commit 4cd8077
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
17 changes: 8 additions & 9 deletions src/ATokenCheckpointed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ contract ATokenCheckpointed is AToken {
mapping(uint256 => ProposalVote) public proposalVotes;

/// @notice The governor contract associated with this governance token. It
/// must be one that supports fractional voting, e.g.
/// GovernorCountingFractional.
IFractionalGovernor public immutable governor;
/// must be one that supports fractional voting, e.g. GovernorCountingFractional.
IFractionalGovernor public immutable GOVERNOR;

/// @notice Mapping from address to stored (not rebased) balance checkpoint history.
mapping(address => Checkpoints.History) private balanceCheckpoints;
Expand All @@ -83,15 +82,15 @@ contract ATokenCheckpointed is AToken {
/// @param _castVoteWindow The number of blocks that users have to express
/// their votes on a proposal before votes can be cast.
constructor(IPool _pool, address _governor, uint32 _castVoteWindow) AToken(_pool) {
governor = IFractionalGovernor(_governor);
GOVERNOR = IFractionalGovernor(_governor);
CAST_VOTE_WINDOW = _castVoteWindow;
}

// TODO Is there a better way to do this? It cannot be done in the constructor
// because the AToken is just a proxy -- it won't share an address with
// the implementation (i.e. this code).
function selfDelegate() public {
IVotingToken(governor.token()).delegate(address(this));
IVotingToken(GOVERNOR.token()).delegate(address(this));
}

/// @notice Method which returns the deadline (as a block number) by which
Expand All @@ -106,7 +105,7 @@ contract ATokenCheckpointed is AToken {
view
returns (uint256 _lastVotingBlock)
{
_lastVotingBlock = governor.proposalDeadline(proposalId) - CAST_VOTE_WINDOW;
_lastVotingBlock = GOVERNOR.proposalDeadline(proposalId) - CAST_VOTE_WINDOW;
}

/// @notice Allow a depositor to express their voting preference for a given
Expand All @@ -117,7 +116,7 @@ contract ATokenCheckpointed is AToken {
/// @param support The depositor's vote preferences in accordance with the `VoteType` enum.
function expressVote(uint256 proposalId, uint8 support) external {
require(!hasCastVotesOnProposal[proposalId], "too late to express, votes already cast");
uint256 weight = getPastStoredBalance(msg.sender, governor.proposalSnapshot(proposalId));
uint256 weight = getPastStoredBalance(msg.sender, GOVERNOR.proposalSnapshot(proposalId));
require(weight > 0, "no weight");

require(!proposalVotersHasVoted[proposalId][msg.sender], "already voted");
Expand Down Expand Up @@ -153,7 +152,7 @@ contract ATokenCheckpointed is AToken {
"no votes expressed"
);

uint256 _proposalSnapshotBlockNumber = governor.proposalSnapshot(proposalId);
uint256 _proposalSnapshotBlockNumber = GOVERNOR.proposalSnapshot(proposalId);

// Use the snapshot of total deposits to determine total voting weight. We cannot
// use the proposalVote numbers alone, since some people with deposits at the
Expand Down Expand Up @@ -187,7 +186,7 @@ contract ATokenCheckpointed is AToken {
hasCastVotesOnProposal[proposalId] = true;
bytes memory fractionalizedVotes =
abi.encodePacked(_forVotesToCast, _againstVotesToCast, _abstainVotesToCast);
governor.castVoteWithReasonAndParams(
GOVERNOR.castVoteWithReasonAndParams(
proposalId, unusedSupportParam, "crowd-sourced vote", fractionalizedVotes
);
}
Expand Down
17 changes: 8 additions & 9 deletions src/ATokenNaive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ contract ATokenNaive is AToken {
mapping(uint256 => ProposalVote) public proposalVotes;

/// @notice The governor contract associated with this governance token. It
/// must be one that supports fractional voting, e.g.
/// GovernorCountingFractional.
IFractionalGovernor public immutable governor;
/// must be one that supports fractional voting, e.g. GovernorCountingFractional.
IFractionalGovernor public immutable GOVERNOR;

/// @notice Mapping from address to deposit checkpoint history.
mapping(address => Checkpoints.History) private depositCheckpoints;
Expand All @@ -83,15 +82,15 @@ contract ATokenNaive is AToken {
/// @param _castVoteWindow The number of blocks that users have to express
/// their votes on a proposal before votes can be cast.
constructor(IPool _pool, address _governor, uint32 _castVoteWindow) AToken(_pool) {
governor = IFractionalGovernor(_governor);
GOVERNOR = IFractionalGovernor(_governor);
CAST_VOTE_WINDOW = _castVoteWindow;
}

// TODO Is there a better way to do this? It cannot be done in the constructor
// because the AToken is just used a proxy -- it won't share an address with
// the implementation (i.e. this code).
function selfDelegate() public {
IVotingToken(governor.token()).delegate(address(this));
IVotingToken(GOVERNOR.token()).delegate(address(this));
}

/// @notice Method which returns the deadline (as a block number) by which
Expand All @@ -106,7 +105,7 @@ contract ATokenNaive is AToken {
view
returns (uint256 _lastVotingBlock)
{
_lastVotingBlock = governor.proposalDeadline(proposalId) - CAST_VOTE_WINDOW;
_lastVotingBlock = GOVERNOR.proposalDeadline(proposalId) - CAST_VOTE_WINDOW;
}

/// @notice Allow a depositor to express their voting preference for a given
Expand All @@ -117,7 +116,7 @@ contract ATokenNaive is AToken {
/// @param support The depositor's vote preferences in accordance with the `VoteType` enum.
function expressVote(uint256 proposalId, uint8 support) external {
require(!hasCastVotesOnProposal[proposalId], "too late to express, votes already cast");
uint256 weight = getPastDeposits(msg.sender, governor.proposalSnapshot(proposalId));
uint256 weight = getPastDeposits(msg.sender, GOVERNOR.proposalSnapshot(proposalId));
require(weight > 0, "no weight");

require(!proposalVotersHasVoted[proposalId][msg.sender], "already voted");
Expand Down Expand Up @@ -153,7 +152,7 @@ contract ATokenNaive is AToken {
"no votes expressed"
);

uint256 _proposalSnapshotBlockNumber = governor.proposalSnapshot(proposalId);
uint256 _proposalSnapshotBlockNumber = GOVERNOR.proposalSnapshot(proposalId);

// Use the snapshot of total deposits to determine total voting weight. We cannot
// use the proposalVote numbers alone, since some people with deposits at the
Expand Down Expand Up @@ -187,7 +186,7 @@ contract ATokenNaive is AToken {
hasCastVotesOnProposal[proposalId] = true;
bytes memory fractionalizedVotes =
abi.encodePacked(_forVotesToCast, _againstVotesToCast, _abstainVotesToCast);
governor.castVoteWithReasonAndParams(
GOVERNOR.castVoteWithReasonAndParams(
proposalId, unusedSupportParam, "crowd-sourced vote", fractionalizedVotes
);
}
Expand Down
24 changes: 12 additions & 12 deletions src/FractionalPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ contract FractionalPool {
uint32 public constant CAST_VOTE_WINDOW = 1200; // In blocks; 4 hours assuming 12 second blocks.

/// @notice The governance token held and lent by this pool.
IVotingToken public immutable token;
IVotingToken public immutable TOKEN;

/// @notice The governor contract associated with this governance token.
IFractionalGovernor public immutable governor;
IFractionalGovernor public immutable GOVERNOR;

/// @notice Map depositor to deposit amount.
mapping(address => uint256) public deposits;
Expand All @@ -73,8 +73,8 @@ contract FractionalPool {
/// @param _token The governance token held and lent by this pool.
/// @param _governor The governor contract associated with this governance token.
constructor(IVotingToken _token, IFractionalGovernor _governor) {
token = _token;
governor = _governor;
TOKEN = _token;
GOVERNOR = _governor;
_token.delegate(address(this));
}

Expand All @@ -86,7 +86,7 @@ contract FractionalPool {
_writeCheckpoint(_checkpoints[msg.sender], _additionFn, _amount);
_writeCheckpoint(_totalDepositCheckpoints, _additionFn, _amount);

token.transferFrom(msg.sender, address(this), _amount); // Assumes revert on failure.
TOKEN.transferFrom(msg.sender, address(this), _amount); // Assumes revert on failure.
}

/// @notice Allow a depositor to withdraw funds previously deposited to the pool.
Expand All @@ -98,23 +98,23 @@ contract FractionalPool {
_writeCheckpoint(_checkpoints[msg.sender], _subtractionFn, _amount);
_writeCheckpoint(_totalDepositCheckpoints, _subtractionFn, _amount);

token.transfer(msg.sender, _amount); // Assumes revert on failure.
TOKEN.transfer(msg.sender, _amount); // Assumes revert on failure.
}

/// @notice Arbitrarily remove tokens from the pool. This is to simulate a borrower, hence the
/// method name. Since this is just a proof-of-concept, nothing else is actually done here.
/// @param _amount The amount to "borrow."
function borrow(uint256 _amount) public {
borrowTotal[msg.sender] += _amount;
token.transfer(msg.sender, _amount);
TOKEN.transfer(msg.sender, _amount);
}

/// @notice Allow a depositor to express their voting preference for a given proposal. Their
/// preference is recorded internally but not moved to the Governor until `castVote` is called.
/// @param proposalId The proposalId in the associated Governor
/// @param support The depositor's vote preferences in accordance with the `VoteType` enum.
function expressVote(uint256 proposalId, uint8 support) external {
uint256 weight = getPastDeposits(msg.sender, governor.proposalSnapshot(proposalId));
uint256 weight = getPastDeposits(msg.sender, GOVERNOR.proposalSnapshot(proposalId));
if (weight == 0) revert("no weight");

if (_proposalVotersHasVoted[proposalId][msg.sender]) revert("already voted");
Expand All @@ -141,7 +141,7 @@ contract FractionalPool {
uint8 unusedSupportParam = uint8(VoteType.Abstain);
ProposalVote memory _proposalVote = proposalVotes[proposalId];

uint256 _proposalSnapshotBlockNumber = governor.proposalSnapshot(proposalId);
uint256 _proposalSnapshotBlockNumber = GOVERNOR.proposalSnapshot(proposalId);

// Use the snapshot of total deposits to determine total voting weight. We cannot
// use the proposalVote numbers alone, since some people with deposits at the
Expand All @@ -150,7 +150,7 @@ contract FractionalPool {

// We need 256 bits because of the multiplication we're about to do.
uint256 _votingWeightAtSnapshot =
token.getPastVotes(address(this), _proposalSnapshotBlockNumber);
TOKEN.getPastVotes(address(this), _proposalSnapshotBlockNumber);

// forVotesRaw forVotesScaled
// --------------------- = ---------------------
Expand All @@ -169,7 +169,7 @@ contract FractionalPool {

bytes memory fractionalizedVotes =
abi.encodePacked(_forVotesToCast, _againstVotesToCast, _abstainVotesToCast);
governor.castVoteWithReasonAndParams(
GOVERNOR.castVoteWithReasonAndParams(
proposalId, unusedSupportParam, "crowd-sourced vote", fractionalizedVotes
);
}
Expand All @@ -182,7 +182,7 @@ contract FractionalPool {
view
returns (uint256 _lastVotingBlock)
{
_lastVotingBlock = governor.proposalDeadline(proposalId) - CAST_VOTE_WINDOW;
_lastVotingBlock = GOVERNOR.proposalDeadline(proposalId) - CAST_VOTE_WINDOW;
}

/// ===========================================================================
Expand Down

0 comments on commit 4cd8077

Please sign in to comment.