Skip to content

Commit

Permalink
Merge pull request #1601 from morpho-dao/fix/is-frozen
Browse files Browse the repository at this point in the history
Add supply and borrow check for isFrozen
  • Loading branch information
pakim249CAL committed Dec 16, 2022
2 parents 2b91c9c + d177f82 commit 9a624c2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/aave-v2/EntryPositionsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ contract EntryPositionsManager is IEntryPositionsManager, PositionsManagerUtils
/// @notice Thrown when someone tries to borrow but the borrow is paused.
error BorrowIsPaused();

/// @notice Thrown when underlying pool is frozen.
error FrozenOnPool();

/// STRUCTS ///

// Struct to avoid stack too deep.
Expand Down Expand Up @@ -90,13 +93,15 @@ contract EntryPositionsManager is IEntryPositionsManager, PositionsManagerUtils
if (_onBehalf == address(0)) revert AddressIsZero();
if (_amount == 0) revert AmountIsZero();
Types.Market memory market = market[_poolToken];
ERC20 underlyingToken = ERC20(market.underlyingToken);

if (!market.isCreated) revert MarketNotCreated();
if (marketPauseStatus[_poolToken].isSupplyPaused) revert SupplyIsPaused();
if (pool.getConfiguration(address(underlyingToken)).getFrozen()) revert FrozenOnPool();

_updateIndexes(_poolToken);
_setSupplying(_onBehalf, borrowMask[_poolToken], true);

ERC20 underlyingToken = ERC20(market.underlyingToken);
underlyingToken.safeTransferFrom(_from, address(this), _amount);

Types.Delta storage delta = deltas[_poolToken];
Expand Down Expand Up @@ -189,8 +194,12 @@ contract EntryPositionsManager is IEntryPositionsManager, PositionsManagerUtils
if (marketPauseStatus[_poolToken].isBorrowPaused) revert BorrowIsPaused();

ERC20 underlyingToken = ERC20(market.underlyingToken);
if (!pool.getConfiguration(address(underlyingToken)).getBorrowingEnabled())
revert BorrowingNotEnabled();
DataTypes.ReserveConfigurationMap memory reserveConfig = pool.getConfiguration(
address(underlyingToken)
);

if (!reserveConfig.getBorrowingEnabled()) revert BorrowingNotEnabled();
if (reserveConfig.getFrozen()) revert FrozenOnPool();

_updateIndexes(_poolToken);
_setBorrowing(msg.sender, borrowMask[_poolToken], true);
Expand Down
6 changes: 1 addition & 5 deletions src/aave-v2/libraries/aave/ReserveConfiguration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ library ReserveConfiguration {
* @param self The reserve configuration
* @return The frozen state
**/
function getFrozen(DataTypes.ReserveConfigurationMap storage self)
internal
view
returns (bool)
{
function getFrozen(DataTypes.ReserveConfigurationMap memory self) internal pure returns (bool) {
return (self.data & ~FROZEN_MASK) != 0;
}

Expand Down
16 changes: 16 additions & 0 deletions test/aave-v2/TestBorrow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,22 @@ contract TestBorrow is TestSetup {
borrower1.borrow(aUsdc, amount);
}

function testCannotBorrowOnFrozenPool() public {
uint256 amount = 10_000 ether;

DataTypes.ReserveConfigurationMap memory reserveConfig = pool.getConfiguration(dai);
reserveConfig.setFrozen(true);

borrower1.approve(dai, amount);
borrower1.supply(aDai, amount);

vm.prank(address(lendingPoolConfigurator));
pool.setConfiguration(dai, reserveConfig.data);

hevm.expectRevert(EntryPositionsManager.FrozenOnPool.selector);
borrower1.borrow(aDai, amount);
}

function testBorrowLargerThanDeltaShouldClearDelta() public {
// Allows only 10 unmatch suppliers.

Expand Down
17 changes: 17 additions & 0 deletions test/aave-v2/TestSupply.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "./setup/TestSetup.sol";

contract TestSupply is TestSetup {
using stdStorage for StdStorage;
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using WadRayMath for uint256;

// There are no available borrowers: all of the supplied amount is supplied to the pool and set `onPool`.
Expand Down Expand Up @@ -264,6 +265,22 @@ contract TestSupply is TestSetup {
supplier1.supply(aDai, amount);
}

function testCannotSupplyOnFrozenPool() public {
uint256 amount = 10_000 ether;

DataTypes.ReserveConfigurationMap memory reserveConfig = pool.getConfiguration(dai);
reserveConfig.setFrozen(true);

vm.prank(address(lendingPoolConfigurator));
pool.setConfiguration(dai, reserveConfig.data);

supplier1.approve(dai, amount);

hevm.expectRevert(EntryPositionsManager.FrozenOnPool.selector);

supplier1.supply(aDai, amount);
}

function testShouldMatchSupplyWithCorrectAmountOfGas() public {
uint256 amount = 100 ether;
createSigners(30);
Expand Down

0 comments on commit 9a624c2

Please sign in to comment.