minter => instaIndex.master()

This commit is contained in:
Thrilok Kumar 2021-03-27 02:18:05 +05:30
parent c072d9767c
commit 6b6e662a6e
3 changed files with 17 additions and 36 deletions

View File

@ -25,20 +25,16 @@ contract TokenDelegate is TokenDelegateStorageV1, TokenEvents {
/**
* @notice Used to initialize the contract during delegator constructor
* @param account The address to recieve initial suppply
* @param minter_ The address of the minter
* @param mintingAllowedAfter_ Timestamp of the next allowed minting
* @param transferPaused_ Flag to make the token non-transferable
*/
function initialize(address account, address minter_, uint mintingAllowedAfter_, bool transferPaused_) public {
function initialize(address account, uint mintingAllowedAfter_, bool transferPaused_) public {
require(mintingAllowedAfter == 0, "Token::initialize: can only initialize once");
require(mintingAllowedAfter_ >= block.timestamp, "Token::constructor: minting can only begin after deployment");
require(msg.sender == minter, "Token::initialize: admin only");
require(account != address(0) && minter_ != address(0), "Token::initialize: invalid address");
require(account != address(0), "Token::initialize: invalid address");
balances[account] = uint96(totalSupply);
emit Transfer(address(0), account, totalSupply);
minter = minter_;
emit MinterChanged(address(0), minter);
mintingAllowedAfter = mintingAllowedAfter_;
transferPaused = transferPaused_;
@ -49,21 +45,10 @@ contract TokenDelegate is TokenDelegateStorageV1, TokenEvents {
}
}
/**
* @notice Change the minter address
* @param minter_ The address of the new minter
*/
function setMinter(address minter_) external {
require(msg.sender == minter, "Tkn::setMinter: only the minter can change the minter address");
emit MinterChanged(minter, minter_);
minter = minter_;
}
/**
* @notice Pause the token transfer
*/
function pauseTransfer() external {
require(msg.sender == minter, "Tkn::pauseTransfer: only the minter can pause token transfer");
function pauseTransfer() external isMaster {
transferPaused = true;
emit TransferPaused(msg.sender);
}
@ -71,8 +56,7 @@ contract TokenDelegate is TokenDelegateStorageV1, TokenEvents {
/**
* @notice Unpause the token transfer
*/
function unpauseTransfer() external {
require(msg.sender == minter, "Tkn::unpauseTransfer: only the minter can unpause token transfer");
function unpauseTransfer() external isMaster {
transferPaused = false;
emit TransferUnpaused(msg.sender);
}
@ -81,8 +65,7 @@ contract TokenDelegate is TokenDelegateStorageV1, TokenEvents {
* @notice Change token name
* @param name_ New token name
*/
function changeName(string calldata name_) external {
require(msg.sender == minter, "Tkn::changeName: only the minter can change token name");
function changeName(string calldata name_) external isMaster {
require(bytes(name_).length > 0, "Tkn::changeName: name_ length invaild");
emit ChangedName(name, name_);
@ -94,8 +77,7 @@ contract TokenDelegate is TokenDelegateStorageV1, TokenEvents {
* @notice Change token symbol
* @param symbol_ New token symbol
*/
function changeSymbol(string calldata symbol_) external {
require(msg.sender == minter, "Tkn::changeSymbol: only the minter can change token symbol");
function changeSymbol(string calldata symbol_) external isMaster {
require(bytes(symbol_).length > 0, "Tkn::changeSymbol: name_name_ length invaild");
emit ChangedName(symbol, symbol_);

View File

@ -6,21 +6,16 @@ import { TokenDelegatorStorage, TokenEvents } from "./TokenInterfaces.sol";
contract TokenDelegator is TokenDelegatorStorage, TokenEvents {
constructor(
address account,
address minter_,
address implementation_,
uint mintingAllowedAfter_,
uint changeImplementationAfter_,
bool transferPaused_
) {
// Admin set to msg.sender for initialization
minter = msg.sender;
delegateTo(
implementation_,
abi.encodeWithSignature(
"initialize(address,address,uint256,bool)",
"initialize(address,uint256,bool)",
account,
minter_,
mintingAllowedAfter_,
transferPaused_
)
@ -29,16 +24,13 @@ contract TokenDelegator is TokenDelegatorStorage, TokenEvents {
changeImplementationAfter = changeImplementationAfter_;
_setImplementation(implementation_);
minter = minter_;
}
/**
* @notice Called by the admin to update the implementation of the delegator
* @param implementation_ The address of the new implementation for delegation
*/
function _setImplementation(address implementation_) public {
require(msg.sender == minter, "TokenDelegator::_setImplementation: admin only");
function _setImplementation(address implementation_) public isMaster {
require(implementation_ != address(0), "TokenDelegator::_setImplementation: invalid implementation address");
require(changeImplementationAfter >= block.timestamp, "TokenDelegator::_setImplementation: can change implementation changeImplementationAfter time only");

View File

@ -1,6 +1,10 @@
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
interface IndexInterface {
function master() external view returns (address);
}
contract TokenEvents {
/// @notice An event thats emitted when an account changes its delegate
@ -35,8 +39,7 @@ contract TokenEvents {
}
contract TokenDelegatorStorage {
/// @notice Administrator Token minter
address public minter;
IndexInterface constant public instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
/// @notice Active brains of Token
address public implementation;
@ -56,6 +59,10 @@ contract TokenDelegatorStorage {
/// @notice EIP-20 token decimals for this token
uint8 public constant decimals = 18;
modifier isMaster() {
require(instaIndex.master() == msg.sender, "Tkn::isMaster: msg.sender not master");
_;
}
}
/**