Skip to content

Commit

Permalink
scopelint fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlaprade committed Dec 15, 2022
1 parent 0e9ae44 commit 2787229
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 72 deletions.
9 changes: 3 additions & 6 deletions src/ATokenCheckpointed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,9 @@ contract ATokenCheckpointed is AToken {
return _userState[_user].balance;
}

function _checkpointRawBalanceOf(
address _user
) internal returns (
uint256 _previousBalance,
uint256 _currentBalance
)
function _checkpointRawBalanceOf(address _user)
internal
returns (uint256 _previousBalance, uint256 _currentBalance)
{
(_previousBalance, _currentBalance) = balanceCheckpoints[_user].push(_rawBalanceOf(_user));
}
Expand Down
89 changes: 33 additions & 56 deletions test/ATokenCheckpointed.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1199,38 +1199,24 @@ contract CastVote is AaveAtokenForkTest {
// These can differ because votes are rounded.
assertApproxEqAbs(_againstVotes + _forVotes + _abstainVotes, _expectedVotingWeight, 1);

// forgefmt: disable-start
if (_vars.supportTypeA == _vars.supportTypeB) {
assertEq(_forVotes, _vars.supportTypeA == uint8(VoteType.For) ? _expectedVotingWeight : 0);
assertEq(
_againstVotes, _vars.supportTypeA == uint8(VoteType.Against) ? _expectedVotingWeight : 0
);
assertEq(
_abstainVotes, _vars.supportTypeA == uint8(VoteType.Abstain) ? _expectedVotingWeight : 0
);
assertEq(_againstVotes, _vars.supportTypeA == uint8(VoteType.Against) ? _expectedVotingWeight : 0);
assertEq(_abstainVotes, _vars.supportTypeA == uint8(VoteType.Abstain) ? _expectedVotingWeight : 0);
} else {
uint256 _expectedVotingWeightA = (_vars.voteWeightA * _expectedVotingWeight) / _initGovBalance;
uint256 _expectedVotingWeightB = (_vars.voteWeightB * _expectedVotingWeight) / _initGovBalance;

// We assert the weight is within a range of 1 because scaled weights are sometimes floored.
if (_vars.supportTypeA == uint8(VoteType.For)) {
assertApproxEqAbs(_forVotes, _expectedVotingWeightA, 1);
}
if (_vars.supportTypeB == uint8(VoteType.For)) {
assertApproxEqAbs(_forVotes, _expectedVotingWeightB, 1);
}
if (_vars.supportTypeA == uint8(VoteType.Against)) {
assertApproxEqAbs(_againstVotes, _expectedVotingWeightA, 1);
}
if (_vars.supportTypeB == uint8(VoteType.Against)) {
assertApproxEqAbs(_againstVotes, _expectedVotingWeightB, 1);
}
if (_vars.supportTypeA == uint8(VoteType.Abstain)) {
assertApproxEqAbs(_abstainVotes, _expectedVotingWeightA, 1);
}
if (_vars.supportTypeB == uint8(VoteType.Abstain)) {
assertApproxEqAbs(_abstainVotes, _expectedVotingWeightB, 1);
}
if (_vars.supportTypeA == uint8(VoteType.For)) assertApproxEqAbs(_forVotes, _expectedVotingWeightA, 1);
if (_vars.supportTypeB == uint8(VoteType.For)) assertApproxEqAbs(_forVotes, _expectedVotingWeightB, 1);
if (_vars.supportTypeA == uint8(VoteType.Against)) assertApproxEqAbs(_againstVotes, _expectedVotingWeightA, 1);
if (_vars.supportTypeB == uint8(VoteType.Against)) assertApproxEqAbs(_againstVotes, _expectedVotingWeightB, 1);
if (_vars.supportTypeA == uint8(VoteType.Abstain)) assertApproxEqAbs(_abstainVotes, _expectedVotingWeightA, 1);
if (_vars.supportTypeB == uint8(VoteType.Abstain)) assertApproxEqAbs(_abstainVotes, _expectedVotingWeightB, 1);
}
// forgefmt: disable-end
}

struct VotingWeightIsAbandonedVars {
Expand Down Expand Up @@ -1323,16 +1309,12 @@ contract CastVote is AaveAtokenForkTest {
1
);

// forgefmt: disable-start
// We assert the weight is within a range of 1 because scaled weights are sometimes floored.
if (_vars.supportTypeA == uint8(VoteType.For)) {
assertApproxEqAbs(_forVotes, _expectedVotingWeightA, 1);
}
if (_vars.supportTypeA == uint8(VoteType.Against)) {
assertApproxEqAbs(_againstVotes, _expectedVotingWeightA, 1);
}
if (_vars.supportTypeA == uint8(VoteType.Abstain)) {
assertApproxEqAbs(_abstainVotes, _expectedVotingWeightA, 1);
}
if (_vars.supportTypeA == uint8(VoteType.For)) assertApproxEqAbs(_forVotes, _expectedVotingWeightA, 1);
if (_vars.supportTypeA == uint8(VoteType.Against)) assertApproxEqAbs(_againstVotes, _expectedVotingWeightA, 1);
if (_vars.supportTypeA == uint8(VoteType.Abstain)) assertApproxEqAbs(_abstainVotes, _expectedVotingWeightA, 1);
// forgefmt: disable-end
}

function _testVotingWeightIsUnaffectedByDepositsAfterProposal(
Expand Down Expand Up @@ -1618,20 +1600,22 @@ contract CastVote is AaveAtokenForkTest {
// Submit votes on behalf of the pool.
aToken.castVote(_proposalId);

(uint256 _againstVotes, uint256 _forVotes, uint256 _abstainVotes ) =
(uint256 _againstVotes, uint256 _forVotes, uint256 _abstainVotes) =
governor.proposalVotes(_proposalId);

if (_supportTypeA == _supportTypeB) {
if (_supportTypeA == uint8(VoteType.For)) assertEq(_forVotes, _weight);
if (_supportTypeA == uint8(VoteType.Against)) assertEq(_againstVotes, _weight);
if (_supportTypeA == uint8(VoteType.Abstain)) assertEq(_abstainVotes, _weight);
} else {
// forgefmt: disable-start
if (_supportTypeA == uint8(VoteType.For)) assertEq(_forVotes, _weight - _transferAmount);
if (_supportTypeA == uint8(VoteType.Against)) assertEq(_againstVotes, _weight - _transferAmount);
if (_supportTypeA == uint8(VoteType.Abstain)) assertEq(_abstainVotes, _weight - _transferAmount);
if (_supportTypeB == uint8(VoteType.For)) assertEq(_forVotes, _transferAmount);
if (_supportTypeB == uint8(VoteType.Against)) assertEq(_againstVotes, _transferAmount);
if (_supportTypeB == uint8(VoteType.Abstain)) assertEq(_abstainVotes, _transferAmount);
// forgefmt: disable-end
}
}
}
Expand Down Expand Up @@ -1686,7 +1670,10 @@ contract GetPastStoredBalanceTest is AaveAtokenForkTest {
// getPastStoredBalance should be able to give us the rebased balance at an
// intermediate point.
assertEq(
aToken.getPastStoredBalance(_who, block.number - (_blocksJumped / 3)),
aToken.getPastStoredBalance(
_who,
block.number - (_blocksJumped / 3) // 1/3 is just an arbitrary point.
),
_rawBalances[0]
);

Expand Down Expand Up @@ -1716,7 +1703,7 @@ contract GetPastStoredBalanceTest is AaveAtokenForkTest {
);
// getPastStoredBalance should be able to give us the raw balance at intermediate points.
assertEq(
aToken.getPastStoredBalance(_who, block.number - _blocksJumpedSecondTime / 3),
aToken.getPastStoredBalance(_who, block.number - _blocksJumpedSecondTime / 3), // random point
_rawBalances[1]
);
assertEq(
Expand All @@ -1742,10 +1729,7 @@ contract GetPastStoredBalanceTest is AaveAtokenForkTest {
aToken.getPastStoredBalance(_who, block.number - _blocksJumpedThirdTime),
aToken.exposedRawBalanceOf(_who)
);
assertEq(
aToken.getPastStoredBalance(_who, block.number - 1),
aToken.exposedRawBalanceOf(_who)
);
assertEq(aToken.getPastStoredBalance(_who, block.number - 1), aToken.exposedRawBalanceOf(_who));
assertGt(
_rawBalances[1], // The raw balance pre-withdrawal.
aToken.getPastStoredBalance(_who, block.number - _blocksJumpedThirdTime)
Expand Down Expand Up @@ -1816,10 +1800,12 @@ contract GetPastTotalDepositsTest is AaveAtokenForkTest {
vm.roll(block.number + 100);
vm.warp(block.timestamp + 100 days);

// forgefmt: disable-start
assertEq(aToken.getPastTotalDeposits(block.number - 101), INITIAL_REBASING_DEPOSIT);
assertEq(aToken.getPastTotalDeposits(block.number - 100), INITIAL_REBASING_DEPOSIT + _rawBalanceA);
assertEq(aToken.getPastTotalDeposits(block.number - 10), INITIAL_REBASING_DEPOSIT + _rawBalanceA);
assertEq(aToken.getPastTotalDeposits(block.number - 1), INITIAL_REBASING_DEPOSIT + _rawBalanceA);
// forgefmt: disable-end

// Another user deposits.
_mintGovAndSupplyToAave(_userB, _amountB);
Expand All @@ -1829,10 +1815,12 @@ contract GetPastTotalDepositsTest is AaveAtokenForkTest {
vm.roll(block.number + 100);
vm.warp(block.timestamp + 100 days);

// forgefmt: disable-start
assertEq(aToken.getPastTotalDeposits(block.number - 201), INITIAL_REBASING_DEPOSIT);
assertEq(aToken.getPastTotalDeposits(block.number - 120), INITIAL_REBASING_DEPOSIT + _rawBalanceA);
assertEq(aToken.getPastTotalDeposits(block.number - 20), INITIAL_REBASING_DEPOSIT + _rawBalanceA + _rawBalanceB);
assertEq(aToken.getPastTotalDeposits(block.number - 1), INITIAL_REBASING_DEPOSIT + _rawBalanceA + _rawBalanceB);
// forgefmt: disable-end
}

function test_GetPastTotalDepositsDecreasesOnWithdraw() public {
Expand All @@ -1849,18 +1837,11 @@ contract GetPastTotalDepositsTest is AaveAtokenForkTest {
vm.roll(block.number + 100);
vm.warp(block.timestamp + 100 days);

assertEq(
aToken.getPastTotalDeposits(block.number - 1),
INITIAL_REBASING_DEPOSIT + _rawBalanceA
);
assertEq(aToken.getPastTotalDeposits(block.number - 1), INITIAL_REBASING_DEPOSIT + _rawBalanceA);

vm.startPrank(_userA);
uint256 _withdrawAmount = aToken.balanceOf(_userA) / 3;
pool.withdraw(
address(govToken),
_withdrawAmount,
_userA
);
pool.withdraw(address(govToken), _withdrawAmount, _userA);
vm.stopPrank();

// Advance the clock so that we checkpoint and let some rebasing happen.
Expand All @@ -1875,8 +1856,7 @@ contract GetPastTotalDepositsTest is AaveAtokenForkTest {
);

assertGt(
aToken.getPastTotalDeposits(block.number - 101),
aToken.getPastTotalDeposits(block.number - 1)
aToken.getPastTotalDeposits(block.number - 101), aToken.getPastTotalDeposits(block.number - 1)
);
}

Expand Down Expand Up @@ -1952,10 +1932,7 @@ contract GetPastTotalDepositsTest is AaveAtokenForkTest {
vm.roll(block.number + 100);
vm.warp(block.timestamp + 100 days);

assertEq(
aToken.getPastTotalDeposits(block.number - 1),
_totalDeposits
);
assertEq(aToken.getPastTotalDeposits(block.number - 1), _totalDeposits);
}

function test_GetPastTotalDepositsZerosOutIfAllPositionsAreUnwound() public {
Expand Down Expand Up @@ -1990,7 +1967,7 @@ contract GetPastTotalDepositsTest is AaveAtokenForkTest {

assertEq(
aToken.getPastTotalDeposits(block.number - 1),
0,
0, // Total deposits should now be zero; any remaining supply belongs to the reserve.
"getPastTotalDeposits accounting is wrong"
);
}
Expand Down
16 changes: 6 additions & 10 deletions test/MockATokenCheckpointed.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// SPDX-License-Identifier: Unlicensed
pragma solidity >=0.8.10;

import { IPool } from 'aave-v3-core/contracts/interfaces/IPool.sol';
import { ATokenCheckpointed } from "src/ATokenCheckpointed.sol";
import {IPool} from "aave-v3-core/contracts/interfaces/IPool.sol";
import {ATokenCheckpointed} from "src/ATokenCheckpointed.sol";

contract MockATokenCheckpointed is ATokenCheckpointed {
constructor(IPool _pool, address _governor, uint32 _castVoteWindow)
ATokenCheckpointed(_pool, _governor, _castVoteWindow)
{}

constructor(
IPool _pool,
address _governor,
uint32 _castVoteWindow
) ATokenCheckpointed(_pool, _governor, _castVoteWindow) {}

function exposedRawBalanceOf(address _user) public returns(uint256) {
function exposedRawBalanceOf(address _user) public returns (uint256) {
return _userState[_user].balance;
}

}

0 comments on commit 2787229

Please sign in to comment.