Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Size permissioned #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions contracts/interfaces/IPoolAddressesProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ interface IPoolAddressesProvider {
*/
event PoolUpdated(address indexed oldAddress, address indexed newAddress);

/**
* @dev Emitted when the Size v2 contract is updated.
* @param oldAddress The old address of the Size v2 contract
* @param newAddress The new address of the Size v2 contract
*/
event SizeUpdated(address indexed oldAddress, address indexed newAddress);

/**
* @dev Emitted when the pool configurator is updated.
* @param oldAddress The old address of the PoolConfigurator
Expand Down Expand Up @@ -145,13 +152,25 @@ interface IPoolAddressesProvider {
*/
function getPool() external view returns (address);

/**
* @notice Returns the address of the Size proxy.
* @return The Size proxy address
*/
function getSize() external view returns (address);

/**
* @notice Updates the implementation of the Pool, or creates a proxy
* setting the new `pool` implementation when the function is called for the first time.
* @param newPoolImpl The new Pool implementation
*/
function setPoolImpl(address newPoolImpl) external;

/**
* @notice Updates the Size v2 contract address
* @param newSize The new Size v2 contract
*/
function setSize(address newSize) external;

/**
* @notice Returns the address of the PoolConfigurator proxy.
* @return The PoolConfigurator proxy address
Expand Down
10 changes: 10 additions & 0 deletions contracts/interfaces/ISize.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

/**
* @title ISize
* @notice Defines the basic interface for Size v2.
*/
interface ISize {
function variablePoolAllowlisted(address account) external returns (bool);
}
10 changes: 10 additions & 0 deletions contracts/mocks/SizeMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;

import {ISize} from './../interfaces/ISize.sol';

contract SizeMock is ISize {
function variablePoolAllowlisted(address) external pure override returns (bool) {
return true;
}
}
13 changes: 13 additions & 0 deletions contracts/protocol/configuration/PoolAddressesProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract PoolAddressesProvider is Ownable, IPoolAddressesProvider {
bytes32 private constant ACL_ADMIN = 'ACL_ADMIN';
bytes32 private constant PRICE_ORACLE_SENTINEL = 'PRICE_ORACLE_SENTINEL';
bytes32 private constant DATA_PROVIDER = 'DATA_PROVIDER';
bytes32 private constant SIZE = 'SIZE';

/**
* @dev Constructor.
Expand Down Expand Up @@ -76,13 +77,25 @@ contract PoolAddressesProvider is Ownable, IPoolAddressesProvider {
return getAddress(POOL);
}

/// @inheritdoc IPoolAddressesProvider
function getSize() external view override returns (address) {
return getAddress(SIZE);
}

/// @inheritdoc IPoolAddressesProvider
function setPoolImpl(address newPoolImpl) external override onlyOwner {
address oldPoolImpl = _getProxyImplementation(POOL);
_updateImpl(POOL, newPoolImpl);
emit PoolUpdated(oldPoolImpl, newPoolImpl);
}

/// @inheritdoc IPoolAddressesProvider
function setSize(address newSize) external override onlyOwner {
address oldSize = _addresses[SIZE];
_addresses[SIZE] = newSize;
emit SizeUpdated(oldSize, newSize);
}

/// @inheritdoc IPoolAddressesProvider
function getPoolConfigurator() external view override returns (address) {
return getAddress(POOL_CONFIGURATOR);
Expand Down
1 change: 1 addition & 0 deletions contracts/protocol/libraries/helpers/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ library Errors {
string public constant SILOED_BORROWING_VIOLATION = '89'; // 'User is trying to borrow multiple assets including a siloed one'
string public constant RESERVE_DEBT_NOT_ZERO = '90'; // the total debt of the reserve needs to be 0
string public constant FLASHLOAN_DISABLED = '91'; // FlashLoaning for this asset is disabled
string public constant CALLER_NOT_SIZE = '92'; // The caller of the function is not the Size v2 contract
}
44 changes: 28 additions & 16 deletions contracts/protocol/pool/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.so
import {IPool} from '../../interfaces/IPool.sol';
import {IACLManager} from '../../interfaces/IACLManager.sol';
import {PoolStorage} from './PoolStorage.sol';
import {ISize} from '../../interfaces/ISize.sol';

/**
* @title Pool contract
Expand Down Expand Up @@ -145,7 +146,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
uint256 amount,
address onBehalfOf,
uint16 referralCode
) public virtual override {
) public virtual override onlySize {
SupplyLogic.executeSupply(
_reserves,
_reservesList,
Expand All @@ -169,7 +170,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
uint8 permitV,
bytes32 permitR,
bytes32 permitS
) public virtual override {
) public virtual override onlySize {
IERC20WithPermit(asset).permit(
msg.sender,
address(this),
Expand Down Expand Up @@ -197,7 +198,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
address asset,
uint256 amount,
address to
) public virtual override returns (uint256) {
) public virtual override onlySize returns (uint256) {
return
SupplyLogic.executeWithdraw(
_reserves,
Expand All @@ -222,7 +223,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
uint256 interestRateMode,
uint16 referralCode,
address onBehalfOf
) public virtual override {
) public virtual override onlySize {
BorrowLogic.executeBorrow(
_reserves,
_reservesList,
Expand Down Expand Up @@ -251,7 +252,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
uint256 amount,
uint256 interestRateMode,
address onBehalfOf
) public virtual override returns (uint256) {
) public virtual override onlySize returns (uint256) {
return
BorrowLogic.executeRepay(
_reserves,
Expand All @@ -277,7 +278,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
uint8 permitV,
bytes32 permitR,
bytes32 permitS
) public virtual override returns (uint256) {
) public virtual override onlySize returns (uint256) {
{
IERC20WithPermit(asset).permit(
msg.sender,
Expand Down Expand Up @@ -306,7 +307,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
address asset,
uint256 amount,
uint256 interestRateMode
) public virtual override returns (uint256) {
) public virtual override onlySize returns (uint256) {
return
BorrowLogic.executeRepay(
_reserves,
Expand All @@ -323,7 +324,10 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
}

/// @inheritdoc IPool
function swapBorrowRateMode(address asset, uint256 interestRateMode) public virtual override {
function swapBorrowRateMode(
address asset,
uint256 interestRateMode
) public virtual override onlySize {
BorrowLogic.executeSwapBorrowRateMode(
_reserves[asset],
_usersConfig[msg.sender],
Expand All @@ -333,15 +337,15 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
}

/// @inheritdoc IPool
function rebalanceStableBorrowRate(address asset, address user) public virtual override {
function rebalanceStableBorrowRate(address asset, address user) public virtual override onlySize {
BorrowLogic.executeRebalanceStableBorrowRate(_reserves[asset], asset, user);
}

/// @inheritdoc IPool
function setUserUseReserveAsCollateral(
address asset,
bool useAsCollateral
) public virtual override {
) public virtual override onlySize {
SupplyLogic.executeUseReserveAsCollateral(
_reserves,
_reservesList,
Expand All @@ -362,7 +366,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
address user,
uint256 debtToCover,
bool receiveAToken
) public virtual override {
) public virtual override onlySize {
LiquidationLogic.executeLiquidationCall(
_reserves,
_reservesList,
Expand Down Expand Up @@ -391,7 +395,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
address onBehalfOf,
bytes calldata params,
uint16 referralCode
) public virtual override {
) public virtual override onlySize {
DataTypes.FlashloanParams memory flashParams = DataTypes.FlashloanParams({
receiverAddress: receiverAddress,
assets: assets,
Expand Down Expand Up @@ -427,7 +431,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
uint256 amount,
bytes calldata params,
uint16 referralCode
) public virtual override {
) public virtual override onlySize {
DataTypes.FlashloanSimpleParams memory flashParams = DataTypes.FlashloanSimpleParams({
receiverAddress: receiverAddress,
asset: asset,
Expand All @@ -441,7 +445,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
}

/// @inheritdoc IPool
function mintToTreasury(address[] calldata assets) external virtual override {
function mintToTreasury(address[] calldata assets) external virtual override onlySize {
PoolLogic.executeMintToTreasury(_reserves, assets);
}

Expand Down Expand Up @@ -678,7 +682,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
}

/// @inheritdoc IPool
function setUserEMode(uint8 categoryId) external virtual override {
function setUserEMode(uint8 categoryId) external virtual override onlySize {
EModeLogic.executeSetUserEMode(
_reserves,
_reservesList,
Expand Down Expand Up @@ -721,7 +725,7 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external virtual override {
) external virtual override onlySize {
SupplyLogic.executeSupply(
_reserves,
_reservesList,
Expand All @@ -734,4 +738,12 @@ contract Pool is VersionedInitializable, PoolStorage, IPool {
})
);
}

modifier onlySize() {
require(
ISize(ADDRESSES_PROVIDER.getSize()).variablePoolAllowlisted(msg.sender),
Errors.CALLER_NOT_SIZE
);
_;
}
}
5 changes: 5 additions & 0 deletions test-suites/helpers/make-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from '@aave/deploy-v3/dist/helpers/contract-getters';
import { tEthereumAddress } from '../../helpers/types';
import { Pool } from '../../types/Pool';
import { SizeMock } from '../../types/mocks/SizeMock';
import { AaveProtocolDataProvider } from '../../types/AaveProtocolDataProvider';
import { MintableERC20 } from '../../types/MintableERC20';
import { AToken } from '../../types/AToken';
Expand Down Expand Up @@ -43,6 +44,7 @@ export interface TestEnv {
riskAdmin: SignerWithAddress;
users: SignerWithAddress[];
pool: Pool;
size: SizeMock;
configurator: PoolConfigurator;
oracle: PriceOracle;
aaveOracle: AaveOracle;
Expand Down Expand Up @@ -74,6 +76,7 @@ const testEnv: TestEnv = {
riskAdmin: {} as SignerWithAddress,
users: [] as SignerWithAddress[],
pool: {} as Pool,
size: {} as SizeMock,
configurator: {} as PoolConfigurator,
helpersContract: {} as AaveProtocolDataProvider,
oracle: {} as PriceOracle,
Expand Down Expand Up @@ -110,9 +113,11 @@ export async function initializeMakeSuite() {
testEnv.emergencyAdmin = testEnv.users[1];
testEnv.riskAdmin = testEnv.users[2];
testEnv.pool = await getPool();
testEnv.size = (await hre.ethers.deployContract('SizeMock')) as SizeMock;
testEnv.configurator = await getPoolConfiguratorProxy();

testEnv.addressesProvider = await getPoolAddressesProvider();
testEnv.addressesProvider.setSize(testEnv.size.address);

testEnv.registry = await getPoolAddressesProviderRegistry();
testEnv.aclManager = await getACLManager();
Expand Down