Skip to content

Commit

Permalink
fix: Bump aave v3 dependencies (#186)
Browse files Browse the repository at this point in the history
* fix: Remove unneccesary waffle dependency

* fix: Bump aave-v3 deploy and core dependencies

* test: Fix tests with new faucet mintable contracts
  • Loading branch information
miguelmtzinf authored Mar 7, 2024
1 parent 551c497 commit d9a89ef
Show file tree
Hide file tree
Showing 14 changed files with 14,349 additions and 27,374 deletions.
23 changes: 22 additions & 1 deletion contracts/mocks/WETH9Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,37 @@ import {WETH9} from '@aave/core-v3/contracts/dependencies/weth/WETH9.sol';
import {Ownable} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/Ownable.sol';

contract WETH9Mock is WETH9, Ownable {
bool internal _protected;

/**
* @dev Function modifier, if _protected is enabled then msg.sender is required to be the owner
*/
modifier onlyOwnerIfProtected() {
if (_protected == true) {
require(owner() == _msgSender(), 'Ownable: caller is not the owner');
}
_;
}

constructor(string memory mockName, string memory mockSymbol, address owner) {
name = mockName;
symbol = mockSymbol;

transferOwnership(owner);
_protected = true;
}

function mint(address account, uint256 value) public onlyOwner returns (bool) {
function mint(address account, uint256 value) public onlyOwnerIfProtected returns (bool) {
balanceOf[account] += value;
emit Transfer(address(0), account, value);
return true;
}

function setProtected(bool state) public onlyOwner {
_protected = state;
}

function isProtected() public view returns (bool) {
return _protected;
}
}
29 changes: 25 additions & 4 deletions contracts/mocks/testnet-helpers/Faucet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {IFaucet} from './IFaucet.sol';
* @dev Ownable Faucet Contract
*/
contract Faucet is IFaucet, Ownable {
/// @inheritdoc IFaucet
uint256 public constant MAX_MINT_AMOUNT = 10000;
uint256 internal maximumMintAmount;

// Mapping to control mint of assets (allowed by default)
mapping(address => bool) internal _nonMintable;
Expand All @@ -20,10 +19,11 @@ contract Faucet is IFaucet, Ownable {
// If disabled, anyone can call mint at the faucet, for PoC environments
bool internal _permissioned;

constructor(address owner, bool permissioned) {
constructor(address owner, bool permissioned, uint256 maxMinAmount) {
require(owner != address(0));
transferOwnership(owner);
_permissioned = permissioned;
maximumMintAmount = maxMinAmount;
}

/**
Expand All @@ -44,7 +44,7 @@ contract Faucet is IFaucet, Ownable {
) external override onlyOwnerIfPermissioned returns (uint256) {
require(!_nonMintable[token], 'Error: not mintable');
require(
amount <= MAX_MINT_AMOUNT * (10 ** TestnetERC20(token).decimals()),
amount <= maximumMintAmount * (10 ** TestnetERC20(token).decimals()),
'Error: Mint limit transaction exceeded'
);

Expand Down Expand Up @@ -81,4 +81,25 @@ contract Faucet is IFaucet, Ownable {
Ownable(childContracts[i]).transferOwnership(newOwner);
}
}

/// @inheritdoc IFaucet
function setProtectedOfChild(
address[] calldata childContracts,
bool state
) external override onlyOwner {
for (uint256 i = 0; i < childContracts.length; i++) {
TestnetERC20(childContracts[i]).setProtected(state);
}
}


/// @inheritdoc IFaucet
function setMaximumMintAmount(uint256 newMaxMintAmount) external override onlyOwner {
maximumMintAmount = newMaxMintAmount;
}

/// @inheritdoc IFaucet
function getMaximumMintAmount() external view override returns (uint256) {
return maximumMintAmount;
}
}
25 changes: 19 additions & 6 deletions contracts/mocks/testnet-helpers/IFaucet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
pragma solidity ^0.8.0;

interface IFaucet {
/**
* @notice Returns the maximum amount of tokens per mint allowed
* @return The maximum amount of tokens per mint allowed
*/
function MAX_MINT_AMOUNT() external pure returns (uint256);

/**
* @notice Function to mint Testnet tokens to the destination address
* @param token The address of the token to perform the mint
Expand Down Expand Up @@ -49,4 +43,23 @@ interface IFaucet {
* @param newOwner The address of the new owner
*/
function transferOwnershipOfChild(address[] calldata childContracts, address newOwner) external;

/**
* @notice Updates protection of minting feature of child token contracts
* @param childContracts A list of child token contract addresses
* @param state True if tokens are only mintable through Faucet, false otherwise
*/
function setProtectedOfChild(address[] calldata childContracts, bool state) external;

/**
* @notice Updates the maximum amount of tokens per mint allowed
* @param newMaxMintAmount The new value of maximum amount of tokens per mint (whole tokens)
*/
function setMaximumMintAmount(uint256 newMaxMintAmount) external;

/**
* @notice Returns the maximum amount of tokens per mint allowed
* @return The maximum amount of tokens per mint allowed (whole tokens)
*/
function getMaximumMintAmount() external view returns (uint256);
}
25 changes: 23 additions & 2 deletions contracts/mocks/testnet-helpers/TestnetERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ contract TestnetERC20 is IERC20WithPermit, ERC20, Ownable {

bytes32 public DOMAIN_SEPARATOR;

bool internal _protected;

/**
* @dev Function modifier, if _protected is enabled then msg.sender is required to be the owner
*/
modifier onlyOwnerIfProtected() {
if (_protected == true) {
require(owner() == _msgSender(), 'Ownable: caller is not the owner');
}
_;
}

constructor(
string memory name,
string memory symbol,
Expand All @@ -41,6 +53,7 @@ contract TestnetERC20 is IERC20WithPermit, ERC20, Ownable {
_setupDecimals(decimals);
require(owner != address(0));
transferOwnership(owner);
_protected = true;
}

/// @inheritdoc IERC20WithPermit
Expand Down Expand Up @@ -74,7 +87,7 @@ contract TestnetERC20 is IERC20WithPermit, ERC20, Ownable {
* @param value The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(uint256 value) public virtual onlyOwner returns (bool) {
function mint(uint256 value) public virtual onlyOwnerIfProtected returns (bool) {
_mint(_msgSender(), value);
return true;
}
Expand All @@ -85,12 +98,20 @@ contract TestnetERC20 is IERC20WithPermit, ERC20, Ownable {
* @param value The amount of tokens to mint.
* @return A boolean that indicates if the operation was successful.
*/
function mint(address account, uint256 value) public virtual onlyOwner returns (bool) {
function mint(address account, uint256 value) public virtual onlyOwnerIfProtected returns (bool) {
_mint(account, value);
return true;
}

function nonces(address owner) public view returns (uint256) {
return _nonces[owner];
}

function setProtected(bool state) public onlyOwner {
_protected = state;
}

function isProtected() public view returns (bool) {
return _protected;
}
}
Loading

0 comments on commit d9a89ef

Please sign in to comment.