Hi. I have a Token contract that was derived from StandaloneERC20. In the minting method (_mint
), the same amount of minted tokens are transfered into a Vesting contract. Since this Vesting contract has a very complicated logic in terms of conditions to release token, I have to call a special function of this Vesting contract, that will register the newly minted token and do some other stuff.
I want to ensure, that only the minting process can execute this function. What would be the best approach?
In StandaloneERC20, a Minter role is defined. Should I pass the same role also to the Vesting contract and pass the onlyMinter
-modifier to this particular method or are there better approaches?
This is my token contract:
contract XXXToken is StandaloneERC20, Ownable {
TeamVesting private _teamVesting;
event TeamVestingAssigned(address teamVesting);
function initialize(
address owner,
address[] memory minters,
address[] memory pausers
) public initializer {
StandaloneERC20.initialize("XXXToken", "XXX", uint8(18), minters, pausers);
Ownable.initialize(owner);
}
function assignTeamVesting(TeamVesting teamVesting) public onlyOwner {
require(address(teamVesting) != address(0));
_teamVesting = teamVesting;
emit TeamVestingAssigned(address(teamVesting));
}
/**
* @dev While minting token special team tokens are granted/vested
* @param account The account of beneficiary who will get the minted token
* @param value The amount of minted token
*/
function _mint(address account, uint256 value) internal whenNotPaused onlyMinter {
super._mint(account, value);
// we give the same amount of token to the team vesting contract
if(address(_teamVesting) != address(0)) {
super._mint(address(_teamVesting), value);
_teamVesting.registerTeamToken(value);
}
}
}
In the function _mint
, a function registerTeamToken
is executed on the TeamVesting-contract. It does some other stuff in order to register when and how many token can released due to detailed terms & conditions.
function registerTeamToken(uint256 value) public {
}
To keep things simple, can I make this function only executable by the Token contract in a different way than to pass a specific role like it was done with onlyMinter
?