Skip to content

Commit

Permalink
IERC20Mintable, not IERC20
Browse files Browse the repository at this point in the history
  • Loading branch information
feuGeneA committed Sep 6, 2024
1 parent 1ea4bfc commit 8b46aa2
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 23 deletions.
43 changes: 32 additions & 11 deletions abi-bindings/go/mocks/ExampleERC20/ExampleERC20.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion contracts/mocks/ExampleERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
ERC20Burnable,
ERC20
} from "@openzeppelin/contracts@5.0.2/token/ERC20/extensions/ERC20Burnable.sol";
import {IERC20Mintable} from "../staking/interfaces/IERC20Mintable.sol";

contract ExampleERC20 is ERC20Burnable {
contract ExampleERC20 is ERC20Burnable, IERC20Mintable {
string private constant _TOKEN_NAME = "Mock Token";
string private constant _TOKEN_SYMBOL = "EXMP";

Expand All @@ -30,4 +31,8 @@ contract ExampleERC20 is ERC20Burnable {

_mint(msg.sender, amount);
}

function mint(address account, uint256 amount) external {
_mint(account, amount);
}
}
17 changes: 10 additions & 7 deletions contracts/staking/ERC20TokenStakingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pragma solidity 0.8.25;
import {IERC20TokenStakingManager} from "./interfaces/IERC20TokenStakingManager.sol";
import {Initializable} from
"@openzeppelin/contracts-upgradeable@5.0.2/proxy/utils/Initializable.sol";
import {IERC20} from "@openzeppelin/contracts@5.0.2/token/ERC20/IERC20.sol";
import {IERC20Mintable} from "./interfaces/IERC20Mintable.sol";
import {SafeERC20TransferFrom} from "@utilities/SafeERC20TransferFrom.sol";
import {SafeERC20} from "@openzeppelin/contracts@5.0.2/token/ERC20/utils/SafeERC20.sol";
import {ICMInitializable} from "../utilities/ICMInitializable.sol";
Expand All @@ -20,13 +20,13 @@ contract ERC20TokenStakingManager is
PoSValidatorManager,
IERC20TokenStakingManager
{
using SafeERC20 for IERC20;
using SafeERC20TransferFrom for IERC20;
using SafeERC20 for IERC20Mintable;
using SafeERC20TransferFrom for IERC20Mintable;

// solhint-disable private-vars-leading-underscore
/// @custom:storage-location erc7201:avalanche-icm.storage.ERC20TokenStakingManager
struct ERC20TokenStakingManagerStorage {
IERC20 _token;
IERC20Mintable _token;
uint8 _tokenDecimals;
}
// solhint-enable private-vars-leading-underscore
Expand Down Expand Up @@ -62,22 +62,25 @@ contract ERC20TokenStakingManager is
*/
function initialize(
PoSValidatorManagerSettings calldata settings,
IERC20 token
IERC20Mintable token
) external reinitializer(2) {
__ERC20TokenStakingManager_init(settings, token);
}

// solhint-disable func-name-mixedcase
function __ERC20TokenStakingManager_init(
PoSValidatorManagerSettings calldata settings,
IERC20 token
IERC20Mintable token
) internal onlyInitializing {
__POS_Validator_Manager_init(settings);
__ERC20TokenStakingManager_init_unchained(token);
}

// solhint-disable func-name-mixedcase
function __ERC20TokenStakingManager_init_unchained(IERC20 token) internal onlyInitializing {
function __ERC20TokenStakingManager_init_unchained(IERC20Mintable token)
internal
onlyInitializing
{
ERC20TokenStakingManagerStorage storage $ = _getERC20StakingManagerStorage();
require(address(token) != address(0), "ERC20TokenStakingManager: zero token address");
$._token = token;
Expand Down
12 changes: 12 additions & 0 deletions contracts/staking/interfaces/IERC20Mintable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// (c) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.25;

import {IERC20} from "@openzeppelin/contracts@5.0.2/token/ERC20/IERC20.sol";

interface IERC20Mintable is IERC20 {
function mint(address account, uint256 amount) external;
}
6 changes: 3 additions & 3 deletions contracts/staking/tests/ERC20TokenStakingManagerTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import {PoSValidatorManagerSettings} from "../interfaces/IPoSValidatorManager.so
import {IRewardCalculator} from "../interfaces/IRewardCalculator.sol";
import {ICMInitializable} from "../../utilities/ICMInitializable.sol";
import {ExampleERC20} from "@mocks/ExampleERC20.sol";
import {IERC20} from "@openzeppelin/contracts@5.0.2/token/ERC20/IERC20.sol";
import {IERC20Mintable} from "../interfaces/IERC20Mintable.sol";
import {SafeERC20} from "@openzeppelin/contracts@5.0.2/token/ERC20/utils/SafeERC20.sol";

// TODO: Remove this once all unit tests implemented
// solhint-disable no-empty-blocks
contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest {
using SafeERC20 for IERC20;
using SafeERC20 for IERC20Mintable;

ERC20TokenStakingManager public app;
IERC20 public token;
IERC20Mintable public token;

function setUp() public virtual {
// Construct the object under test
Expand Down

0 comments on commit 8b46aa2

Please sign in to comment.