From 5872838bf2f4b6aee4f032367f353c6a2998731a Mon Sep 17 00:00:00 2001 From: Kiryl Yermakou Date: Tue, 5 Dec 2023 11:28:58 -0500 Subject: [PATCH 1/5] refactor(ITS): distributor -> minter --- contracts/InterchainTokenFactory.sol | 52 +++++++--------- contracts/InterchainTokenService.sol | 46 ++++++-------- .../interchain-token/InterchainToken.sol | 28 ++++----- contracts/interfaces/IDistributable.sol | 32 +++++----- contracts/interfaces/IERC20BurnableFrom.sol | 2 +- .../interfaces/IERC20MintableBurnable.sol | 4 +- contracts/interfaces/IInterchainToken.sol | 10 +-- .../interfaces/IInterchainTokenDeployer.sol | 4 +- .../interfaces/IInterchainTokenFactory.sol | 10 +-- .../interfaces/IInterchainTokenService.sol | 8 +-- contracts/test/TestBaseInterchainToken.sol | 8 +-- contracts/test/TestFeeOnTransferToken.sol | 6 +- contracts/test/TestMintableBurnableERC20.sol | 6 +- contracts/test/utils/TestDistributable.sol | 10 +-- contracts/utils/Distributable.sol | 48 +++++++------- contracts/utils/InterchainTokenDeployer.sol | 6 +- contracts/utils/RolesConstants.sol | 2 +- test/InterchainToken.js | 13 ++-- test/InterchainTokenFactory.js | 62 +++++++++---------- test/InterchainTokenService.js | 36 +++++------ test/InterchainTokenServiceFullFlow.js | 32 +++++----- test/UtilsTest.js | 60 +++++++++--------- 22 files changed, 228 insertions(+), 257 deletions(-) diff --git a/contracts/InterchainTokenFactory.sol b/contracts/InterchainTokenFactory.sol index fa01c65d..0a376cfc 100644 --- a/contracts/InterchainTokenFactory.sol +++ b/contracts/InterchainTokenFactory.sol @@ -114,13 +114,13 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M /** * @notice Deploys a new interchain token with specified parameters. - * @dev Creates a new token and optionally mints an initial amount to a specified distributor. + * @dev Creates a new token and optionally mints an initial amount to a specified minter. * @param salt The unique salt for deploying the token. * @param name The name of the token. * @param symbol The symbol of the token. * @param decimals The number of decimals for the token. * @param initialSupply The amount of tokens to mint initially (can be zero). - * @param distributor The address to receive the initially minted tokens. + * @param minter The address to receive the initially minted tokens. */ function deployInterchainToken( bytes32 salt, @@ -128,19 +128,19 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M string calldata symbol, uint8 decimals, uint256 initialSupply, - address distributor + address minter ) external payable { address sender = msg.sender; salt = interchainTokenSalt(chainNameHash, sender, salt); - bytes memory distributorBytes = new bytes(0); + bytes memory minterBytes; if (initialSupply > 0) { - distributorBytes = address(this).toBytes(); - } else if (distributor != address(0)) { - distributorBytes = distributor.toBytes(); + minterBytes = address(this).toBytes(); + } else if (minter != address(0)) { + minterBytes = minter.toBytes(); } - _deployInterchainToken(salt, '', name, symbol, decimals, distributorBytes, 0); + _deployInterchainToken(salt, '', name, symbol, decimals, minterBytes, 0); if (initialSupply > 0) { bytes32 tokenId = service.interchainTokenId(TOKEN_FACTORY_DEPLOYER, salt); @@ -150,14 +150,14 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M _setDeployerTokenBalance(tokenId, sender, initialSupply); token.mint(address(this), initialSupply); - token.transferDistributorship(distributor); + token.transferMinterRole(minter); tokenManager.removeFlowLimiter(address(this)); - // If distributor == address(0), we still set it as a flow limiter for consistency with the remote token manager. - tokenManager.addFlowLimiter(distributor); + // If minter == address(0), we still set it as a flow limiter for consistency with the remote token manager. + tokenManager.addFlowLimiter(minter); - tokenManager.transferOperatorship(distributor); + tokenManager.transferOperatorship(minter); } } @@ -165,21 +165,21 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M * @notice Deploys a remote interchain token on a specified destination chain. * @param originalChainName The name of the chain where the token originally exists. * @param salt The unique salt for deploying the token. - * @param distributor The address to distribute the token on the destination chain. + * @param minter The address to distribute the token on the destination chain. * @param destinationChain The name of the destination chain. * @param gasValue The amount of gas to send for the deployment. */ function deployRemoteInterchainToken( string calldata originalChainName, bytes32 salt, - address distributor, + address minter, string memory destinationChain, uint256 gasValue ) external payable { string memory tokenName; string memory tokenSymbol; uint8 tokenDecimals; - bytes memory distributor_ = new bytes(0); + bytes memory minter_; { bytes32 chainNameHash_; @@ -199,14 +199,14 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M tokenSymbol = token.symbol(); tokenDecimals = token.decimals(); - if (distributor != address(0)) { - if (!token.isDistributor(distributor)) revert NotDistributor(distributor); + if (minter != address(0)) { + if (!token.isMinter(minter)) revert NotMinter(minter); - distributor_ = distributor.toBytes(); + minter_ = minter.toBytes(); } } - _deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, distributor_, gasValue); + _deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, minter_, gasValue); } /** @@ -216,7 +216,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M * @param tokenName The name of the token. * @param tokenSymbol The symbol of the token. * @param tokenDecimals The number of decimals for the token. - * @param distributor The address to receive the initially minted tokens. + * @param minter The address to receive the initially minted tokens. * @param gasValue The amount of gas to send for the transfer. */ function _deployInterchainToken( @@ -225,19 +225,11 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M string memory tokenName, string memory tokenSymbol, uint8 tokenDecimals, - bytes memory distributor, + bytes memory minter, uint256 gasValue ) internal { // slither-disable-next-line arbitrary-send-eth - service.deployInterchainToken{ value: gasValue }( - salt, - destinationChain, - tokenName, - tokenSymbol, - tokenDecimals, - distributor, - gasValue - ); + service.deployInterchainToken{ value: gasValue }(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, minter, gasValue); } /** diff --git a/contracts/InterchainTokenService.sol b/contracts/InterchainTokenService.sol index b3b903ac..c1431615 100644 --- a/contracts/InterchainTokenService.sol +++ b/contracts/InterchainTokenService.sol @@ -291,14 +291,14 @@ contract InterchainTokenService is /** * @notice Used to deploy an interchain token alongside a TokenManager in another chain. * @dev At least the `gasValue` amount of native token must be passed to the function call. `gasValue` exists because this function can be - * part of a multicall involving multiple functions that could make remote contract calls. If the `distributor` parameter is empty bytes then + * part of a multicall involving multiple functions that could make remote contract calls. If the `minter` parameter is empty bytes then * a mint/burn TokenManager is used, otherwise a lock/unlock TokenManager is used. * @param salt The salt to be used during deployment. * @param destinationChain The name of the destination chain to deploy to. * @param name The name of the token to be deployed. * @param symbol The symbol of the token to be deployed. * @param decimals The decimals of the token to be deployed. - * @param distributor The address that will be able to mint and burn the deployed token. + * @param minter The address that will be able to mint and burn the deployed token. * @param gasValue The amount of native tokens to be used to pay for gas for the remote deployment. */ function deployInterchainToken( @@ -307,7 +307,7 @@ contract InterchainTokenService is string memory name, string memory symbol, uint8 decimals, - bytes memory distributor, + bytes memory minter, uint256 gasValue ) external payable whenNotPaused { address deployer = msg.sender; @@ -317,11 +317,11 @@ contract InterchainTokenService is bytes32 tokenId = interchainTokenId(deployer, salt); if (bytes(destinationChain).length == 0) { - address tokenAddress = _deployInterchainToken(tokenId, distributor, name, symbol, decimals); + address tokenAddress = _deployInterchainToken(tokenId, minter, name, symbol, decimals); - _deployTokenManager(tokenId, TokenManagerType.MINT_BURN, abi.encode(distributor, tokenAddress)); + _deployTokenManager(tokenId, TokenManagerType.MINT_BURN, abi.encode(minter, tokenAddress)); } else { - _deployRemoteInterchainToken(tokenId, name, symbol, decimals, distributor, destinationChain, gasValue); + _deployRemoteInterchainToken(tokenId, name, symbol, decimals, minter, destinationChain, gasValue); } } @@ -733,15 +733,15 @@ contract InterchainTokenService is * @param payload The encoded data payload to be processed. */ function _processDeployInterchainTokenPayload(bytes calldata payload) internal { - (, bytes32 tokenId, string memory name, string memory symbol, uint8 decimals, bytes memory distributorBytes) = abi.decode( + (, bytes32 tokenId, string memory name, string memory symbol, uint8 decimals, bytes memory minterBytes) = abi.decode( payload, (uint256, bytes32, string, string, uint8, bytes) ); address tokenAddress; - tokenAddress = _deployInterchainToken(tokenId, distributorBytes, name, symbol, decimals); + tokenAddress = _deployInterchainToken(tokenId, minterBytes, name, symbol, decimals); - _deployTokenManager(tokenId, TokenManagerType.MINT_BURN, abi.encode(distributorBytes, tokenAddress)); + _deployTokenManager(tokenId, TokenManagerType.MINT_BURN, abi.encode(minterBytes, tokenAddress)); } /** @@ -798,7 +798,7 @@ contract InterchainTokenService is * @param name The name of the token. * @param symbol The symbol of the token. * @param decimals The number of decimals of the token. - * @param distributor The distributor address for the token. + * @param minter The minter address for the token. * @param destinationChain The destination chain where the token will be deployed. * @param gasValue The amount of gas to be paid for the transaction. */ @@ -807,7 +807,7 @@ contract InterchainTokenService is string memory name, string memory symbol, uint8 decimals, - bytes memory distributor, + bytes memory minter, string calldata destinationChain, uint256 gasValue ) internal { @@ -815,9 +815,9 @@ contract InterchainTokenService is validTokenManagerAddress(tokenId); // slither-disable-next-line reentrancy-events - emit InterchainTokenDeploymentStarted(tokenId, name, symbol, decimals, distributor, destinationChain); + emit InterchainTokenDeploymentStarted(tokenId, name, symbol, decimals, minter, destinationChain); - bytes memory payload = abi.encode(MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, name, symbol, decimals, distributor); + bytes memory payload = abi.encode(MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, name, symbol, decimals, minter); _callContract(destinationChain, payload, gasValue); } @@ -859,33 +859,25 @@ contract InterchainTokenService is /** * @notice Deploys an interchain token. * @param tokenId The ID of the token. - * @param distributorBytes The distributor address for the token. + * @param minterBytes The minter address for the token. * @param name The name of the token. * @param symbol The symbol of the token. * @param decimals The number of decimals of the token. */ function _deployInterchainToken( bytes32 tokenId, - bytes memory distributorBytes, + bytes memory minterBytes, string memory name, string memory symbol, uint8 decimals ) internal returns (address tokenAddress) { bytes32 salt = _getInterchainTokenSalt(tokenId); - address distributor; - if (bytes(distributorBytes).length != 0) distributor = distributorBytes.toAddress(); + address minter; + if (bytes(minterBytes).length != 0) minter = minterBytes.toAddress(); (bool success, bytes memory returnData) = interchainTokenDeployer.delegatecall( - abi.encodeWithSelector( - IInterchainTokenDeployer.deployInterchainToken.selector, - salt, - tokenId, - distributor, - name, - symbol, - decimals - ) + abi.encodeWithSelector(IInterchainTokenDeployer.deployInterchainToken.selector, salt, tokenId, minter, name, symbol, decimals) ); if (!success) { revert InterchainTokenDeploymentFailed(returnData); @@ -896,7 +888,7 @@ contract InterchainTokenService is } // slither-disable-next-line reentrancy-events - emit InterchainTokenDeployed(tokenId, tokenAddress, distributor, name, symbol, decimals); + emit InterchainTokenDeployed(tokenId, tokenAddress, minter, name, symbol, decimals); } /** diff --git a/contracts/interchain-token/InterchainToken.sol b/contracts/interchain-token/InterchainToken.sol index dc510420..e966529b 100644 --- a/contracts/interchain-token/InterchainToken.sol +++ b/contracts/interchain-token/InterchainToken.sol @@ -77,18 +77,12 @@ contract InterchainToken is BaseInterchainToken, ERC20Permit, Distributable, IIn /** * @notice Setup function to initialize contract parameters. * @param tokenId_ The tokenId of the token. - * @param distributor The address of the token distributor. + * @param minter The address of the token minter. * @param tokenName The name of the token. * @param tokenSymbol The symbopl of the token. * @param tokenDecimals The decimals of the token. */ - function init( - bytes32 tokenId_, - address distributor, - string calldata tokenName, - string calldata tokenSymbol, - uint8 tokenDecimals - ) external { + function init(bytes32 tokenId_, address minter, string calldata tokenName, string calldata tokenSymbol, uint8 tokenDecimals) external { if (_isInitialized()) revert AlreadyInitialized(); _initialize(); @@ -102,33 +96,33 @@ contract InterchainToken is BaseInterchainToken, ERC20Permit, Distributable, IIn tokenId = tokenId_; /** - * @dev Set the token service as a distributor to allow it to mint and burn tokens. - * Also add the provided address as a distributor. If `address(0)` was provided, - * add it as a distributor to allow anyone to easily check that no custom distributor was set. + * @dev Set the token service as a minter to allow it to mint and burn tokens. + * Also add the provided address as a minter. If `address(0)` was provided, + * add it as a minter to allow anyone to easily check that no custom minter was set. */ - _addDistributor(interchainTokenService_); - _addDistributor(distributor); + _addMinter(interchainTokenService_); + _addMinter(minter); _setNameHash(tokenName); } /** * @notice Function to mint new tokens. - * @dev Can only be called by the distributor address. + * @dev Can only be called by the minter address. * @param account The address that will receive the minted tokens. * @param amount The amount of tokens to mint. */ - function mint(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function mint(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { _mint(account, amount); } /** * @notice Function to burn tokens. - * @dev Can only be called by the distributor address. + * @dev Can only be called by the minter address. * @param account The address that will have its tokens burnt. * @param amount The amount of tokens to burn. */ - function burn(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function burn(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { _burn(account, amount); } } diff --git a/contracts/interfaces/IDistributable.sol b/contracts/interfaces/IDistributable.sol index c98f400d..3456e674 100644 --- a/contracts/interfaces/IDistributable.sol +++ b/contracts/interfaces/IDistributable.sol @@ -7,34 +7,34 @@ import { IRolesBase } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/in /** * @title IDistributable Interface * @notice An interface for a contract module which provides a basic access control mechanism, where - * there is an account (a distributor) that can be granted exclusive access to specific functions. + * there is an account (a minter) that can be granted exclusive access to specific functions. */ interface IDistributable is IRolesBase { /** - * @notice Change the distributor of the contract. - * @dev Can only be called by the current distributor. - * @param distributor_ The address of the new distributor. + * @notice Change the minter of the contract. + * @dev Can only be called by the current minter. + * @param minter_ The address of the new minter. */ - function transferDistributorship(address distributor_) external; + function transferMinterRole(address minter_) external; /** - * @notice Proposed a change of the distributor of the contract. - * @dev Can only be called by the current distributor. - * @param distributor_ The address of the new distributor. + * @notice Proposed a change of the minter of the contract. + * @dev Can only be called by the current minter. + * @param minter_ The address of the new minter. */ - function proposeDistributorship(address distributor_) external; + function proposeMinterRole(address minter_) external; /** - * @notice Accept a change of the distributor of the contract. - * @dev Can only be called by the proposed distributor. - * @param fromDistributor The previous distributor. + * @notice Accept a change of the minter of the contract. + * @dev Can only be called by the proposed minter. + * @param fromMinter The previous minter. */ - function acceptDistributorship(address fromDistributor) external; + function acceptMinterRole(address fromMinter) external; /** - * @notice Query if an address is a distributor + * @notice Query if an address is a minter * @param addr the address to query for - * @return bool Boolean value representing whether or not the address is a distributor. + * @return bool Boolean value representing whether or not the address is a minter. */ - function isDistributor(address addr) external view returns (bool); + function isMinter(address addr) external view returns (bool); } diff --git a/contracts/interfaces/IERC20BurnableFrom.sol b/contracts/interfaces/IERC20BurnableFrom.sol index cc054d94..048609a7 100644 --- a/contracts/interfaces/IERC20BurnableFrom.sol +++ b/contracts/interfaces/IERC20BurnableFrom.sol @@ -10,7 +10,7 @@ interface IERC20BurnableFrom { /** * @notice Function to burn tokens. * @dev Requires the caller to have allowance for `amount` on `from`. - * Can only be called by the distributor address. + * Can only be called by the minter address. * @param from The address that will have its tokens burnt. * @param amount The amount of tokens to burn. */ diff --git a/contracts/interfaces/IERC20MintableBurnable.sol b/contracts/interfaces/IERC20MintableBurnable.sol index a84f880d..4c909fbc 100644 --- a/contracts/interfaces/IERC20MintableBurnable.sol +++ b/contracts/interfaces/IERC20MintableBurnable.sol @@ -9,7 +9,7 @@ pragma solidity ^0.8.0; interface IERC20MintableBurnable { /** * @notice Function to mint new tokens. - * @dev Can only be called by the distributor address. + * @dev Can only be called by the minter address. * @param to The address that will receive the minted tokens. * @param amount The amount of tokens to mint. */ @@ -17,7 +17,7 @@ interface IERC20MintableBurnable { /** * @notice Function to burn tokens. - * @dev Can only be called by the distributor address. + * @dev Can only be called by the minter address. * @param from The address that will have its tokens burnt. * @param amount The amount of tokens to burn. */ diff --git a/contracts/interfaces/IInterchainToken.sol b/contracts/interfaces/IInterchainToken.sol index 042c5861..ddd760e7 100644 --- a/contracts/interfaces/IInterchainToken.sol +++ b/contracts/interfaces/IInterchainToken.sol @@ -34,16 +34,10 @@ interface IInterchainToken is IInterchainTokenStandard, IDistributable, IERC20Mi /** * @notice Setup function to initialize contract parameters. * @param tokenId_ The tokenId of the token. - * @param distributor The address of the token distributor. + * @param minter The address of the token minter. * @param tokenName The name of the token. * @param tokenSymbol The symbopl of the token. * @param tokenDecimals The decimals of the token. */ - function init( - bytes32 tokenId_, - address distributor, - string calldata tokenName, - string calldata tokenSymbol, - uint8 tokenDecimals - ) external; + function init(bytes32 tokenId_, address minter, string calldata tokenName, string calldata tokenSymbol, uint8 tokenDecimals) external; } diff --git a/contracts/interfaces/IInterchainTokenDeployer.sol b/contracts/interfaces/IInterchainTokenDeployer.sol index 965f1f1c..753356b3 100644 --- a/contracts/interfaces/IInterchainTokenDeployer.sol +++ b/contracts/interfaces/IInterchainTokenDeployer.sol @@ -27,7 +27,7 @@ interface IInterchainTokenDeployer { * @notice Deploys a new instance of the InterchainTokenProxy contract. * @param salt The salt used by Create3Deployer. * @param tokenId tokenId of the token. - * @param distributor Address of the distributor. + * @param minter Address of the minter. * @param name Name of the token. * @param symbol Symbol of the token. * @param decimals Decimals of the token. @@ -36,7 +36,7 @@ interface IInterchainTokenDeployer { function deployInterchainToken( bytes32 salt, bytes32 tokenId, - address distributor, + address minter, string calldata name, string calldata symbol, uint8 decimals diff --git a/contracts/interfaces/IInterchainTokenFactory.sol b/contracts/interfaces/IInterchainTokenFactory.sol index 6a0b5435..b272caae 100644 --- a/contracts/interfaces/IInterchainTokenFactory.sol +++ b/contracts/interfaces/IInterchainTokenFactory.sol @@ -9,7 +9,7 @@ pragma solidity ^0.8.0; interface IInterchainTokenFactory { error ZeroAddress(); error InvalidChainName(); - error NotDistributor(address distributor); + error NotMinter(address minter); error NotOperator(address operator); error InsufficientBalance(bytes32 tokenId, address deployer, uint256 balance); error ApproveFailed(); @@ -53,7 +53,7 @@ interface IInterchainTokenFactory { * @param symbol The symbol of the token. * @param decimals The number of decimals for the token. * @param initialSupply The amount of tokens to mint initially (can be zero). - * @param distributor The address to receive the initially minted tokens. + * @param minter The address to receive the initially minted tokens. */ function deployInterchainToken( bytes32 salt, @@ -61,21 +61,21 @@ interface IInterchainTokenFactory { string calldata symbol, uint8 decimals, uint256 initialSupply, - address distributor + address minter ) external payable; /** * @notice Deploys a remote interchain token on a specified destination chain. * @param originalChainName The name of the chain where the token originally exists. * @param salt The unique salt for deploying the token. - * @param distributor The address to distribute the token on the destination chain. + * @param minter The address to distribute the token on the destination chain. * @param destinationChain The name of the destination chain. * @param gasValue The amount of gas to send for the deployment. */ function deployRemoteInterchainToken( string calldata originalChainName, bytes32 salt, - address distributor, + address minter, string memory destinationChain, uint256 gasValue ) external payable; diff --git a/contracts/interfaces/IInterchainTokenService.sol b/contracts/interfaces/IInterchainTokenService.sol index 07b02027..f14d2d2f 100644 --- a/contracts/interfaces/IInterchainTokenService.sol +++ b/contracts/interfaces/IInterchainTokenService.sol @@ -70,14 +70,14 @@ interface IInterchainTokenService is string tokenName, string tokenSymbol, uint8 tokenDecimals, - bytes distributor, + bytes minter, string destinationChain ); event TokenManagerDeployed(bytes32 indexed tokenId, address tokenManager, TokenManagerType indexed tokenManagerType, bytes params); event InterchainTokenDeployed( bytes32 indexed tokenId, address tokenAddress, - address indexed distributor, + address indexed minter, string name, string symbol, uint8 decimals @@ -174,7 +174,7 @@ interface IInterchainTokenService is * @param name The name of the interchain tokens. * @param symbol The symbol of the interchain tokens. * @param decimals The number of decimals for the interchain tokens. - * @param distributor The distributor data for mint/burn operations. + * @param minter The minter data for mint/burn operations. * @param gasValue The gas value for deployment. */ function deployInterchainToken( @@ -183,7 +183,7 @@ interface IInterchainTokenService is string memory name, string memory symbol, uint8 decimals, - bytes memory distributor, + bytes memory minter, uint256 gasValue ) external payable; diff --git a/contracts/test/TestBaseInterchainToken.sol b/contracts/test/TestBaseInterchainToken.sol index be7ee971..5bdaa1de 100644 --- a/contracts/test/TestBaseInterchainToken.sol +++ b/contracts/test/TestBaseInterchainToken.sol @@ -20,7 +20,7 @@ contract TestBaseInterchainToken is BaseInterchainToken, Distributable, IERC20Mi name = name_; symbol = symbol_; decimals = decimals_; - _addDistributor(msg.sender); + _addMinter(msg.sender); service = service_; tokenId = tokenId_; } @@ -56,15 +56,15 @@ contract TestBaseInterchainToken is BaseInterchainToken, Distributable, IERC20Mi tokenManagerRequiresApproval_ = requiresApproval; } - function mint(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function mint(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { _mint(account, amount); } - function burn(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function burn(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { _burn(account, amount); } - function burnFrom(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function burnFrom(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { uint256 currentAllowance = allowance[account][msg.sender]; if (currentAllowance < amount) revert AllowanceExceeded(); _approve(account, msg.sender, currentAllowance - amount); diff --git a/contracts/test/TestFeeOnTransferToken.sol b/contracts/test/TestFeeOnTransferToken.sol index 34942b5f..f975c663 100644 --- a/contracts/test/TestFeeOnTransferToken.sol +++ b/contracts/test/TestFeeOnTransferToken.sol @@ -19,7 +19,7 @@ contract TestFeeOnTransferToken is BaseInterchainToken, Distributable, IERC20Min name = name_; symbol = symbol_; decimals = decimals_; - _addDistributor(msg.sender); + _addMinter(msg.sender); service = service_; tokenId = tokenId_; } @@ -55,11 +55,11 @@ contract TestFeeOnTransferToken is BaseInterchainToken, Distributable, IERC20Min tokenManagerRequiresApproval_ = requiresApproval; } - function mint(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function mint(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { _mint(account, amount); } - function burn(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function burn(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { _burn(account, amount); } diff --git a/contracts/test/TestMintableBurnableERC20.sol b/contracts/test/TestMintableBurnableERC20.sol index 32b717a1..6a26211e 100644 --- a/contracts/test/TestMintableBurnableERC20.sol +++ b/contracts/test/TestMintableBurnableERC20.sol @@ -15,14 +15,14 @@ contract TestMintableBurnableERC20 is ERC20, Distributable, IERC20MintableBurnab name = name_; symbol = symbol_; decimals = decimals_; - _addDistributor(msg.sender); + _addMinter(msg.sender); } - function mint(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function mint(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { _mint(account, amount); } - function burn(address account, uint256 amount) external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function burn(address account, uint256 amount) external onlyRole(uint8(Roles.MINTER)) { _burn(account, amount); } } diff --git a/contracts/test/utils/TestDistributable.sol b/contracts/test/utils/TestDistributable.sol index 22d607ad..4b3c22c7 100644 --- a/contracts/test/utils/TestDistributable.sol +++ b/contracts/test/utils/TestDistributable.sol @@ -7,15 +7,15 @@ import { Distributable } from '../../utils/Distributable.sol'; contract TestDistributable is Distributable { uint256 public nonce; - constructor(address distributor) { - _addDistributor(distributor); + constructor(address minter) { + _addMinter(minter); } - function testDistributable() external onlyRole(uint8(Roles.DISTRIBUTOR)) { + function testDistributable() external onlyRole(uint8(Roles.MINTER)) { nonce++; } - function distributorRole() external pure returns (uint8) { - return uint8(Roles.DISTRIBUTOR); + function minterRole() external pure returns (uint8) { + return uint8(Roles.MINTER); } } diff --git a/contracts/utils/Distributable.sol b/contracts/utils/Distributable.sol index 6e2dfc7a..73bcc9af 100644 --- a/contracts/utils/Distributable.sol +++ b/contracts/utils/Distributable.sol @@ -10,52 +10,52 @@ import { RolesConstants } from './RolesConstants.sol'; /** * @title Distributable Contract * @notice A contract module which provides a basic access control mechanism, where - * there is an account (a distributor) that can be granted exclusive access to + * there is an account (a minter) that can be granted exclusive access to * specific functions. * @dev This module is used through inheritance. */ contract Distributable is IDistributable, RolesBase, RolesConstants { /** - * @notice Internal function that stores the new distributor address in the correct storage slot. - * @param distributor_ The address of the new distributor. + * @notice Internal function that stores the new minter address in the correct storage slot. + * @param minter_ The address of the new minter. */ - function _addDistributor(address distributor_) internal { - _addRole(distributor_, uint8(Roles.DISTRIBUTOR)); + function _addMinter(address minter_) internal { + _addRole(minter_, uint8(Roles.MINTER)); } /** - * @notice Changes the distributor of the contract. - * @dev Can only be called by the current distributor. - * @param distributor_ The address of the new distributor. + * @notice Changes the minter of the contract. + * @dev Can only be called by the current minter. + * @param minter_ The address of the new minter. */ - function transferDistributorship(address distributor_) external onlyRole(uint8(Roles.DISTRIBUTOR)) { - _transferRole(msg.sender, distributor_, uint8(Roles.DISTRIBUTOR)); + function transferMinterRole(address minter_) external onlyRole(uint8(Roles.MINTER)) { + _transferRole(msg.sender, minter_, uint8(Roles.MINTER)); } /** - * @notice Proposes a change of the distributor of the contract. - * @dev Can only be called by the current distributor. - * @param distributor_ The address of the new distributor. + * @notice Proposes a change of the minter of the contract. + * @dev Can only be called by the current minter. + * @param minter_ The address of the new minter. */ - function proposeDistributorship(address distributor_) external onlyRole(uint8(Roles.DISTRIBUTOR)) { - _proposeRole(msg.sender, distributor_, uint8(Roles.DISTRIBUTOR)); + function proposeMinterRole(address minter_) external onlyRole(uint8(Roles.MINTER)) { + _proposeRole(msg.sender, minter_, uint8(Roles.MINTER)); } /** - * @notice Accept a change of the distributor of the contract. - * @dev Can only be called by the proposed distributor. - * @param fromDistributor The previous distributor. + * @notice Accept a change of the minter of the contract. + * @dev Can only be called by the proposed minter. + * @param fromMinter The previous minter. */ - function acceptDistributorship(address fromDistributor) external { - _acceptRole(fromDistributor, msg.sender, uint8(Roles.DISTRIBUTOR)); + function acceptMinterRole(address fromMinter) external { + _acceptRole(fromMinter, msg.sender, uint8(Roles.MINTER)); } /** - * @notice Query if an address is a distributor + * @notice Query if an address is a minter * @param addr the address to query for - * @return bool Boolean value representing whether or not the address is a distributor. + * @return bool Boolean value representing whether or not the address is a minter. */ - function isDistributor(address addr) external view returns (bool) { - return hasRole(addr, uint8(Roles.DISTRIBUTOR)); + function isMinter(address addr) external view returns (bool) { + return hasRole(addr, uint8(Roles.MINTER)); } } diff --git a/contracts/utils/InterchainTokenDeployer.sol b/contracts/utils/InterchainTokenDeployer.sol index 28ff1c56..f5c07045 100644 --- a/contracts/utils/InterchainTokenDeployer.sol +++ b/contracts/utils/InterchainTokenDeployer.sol @@ -28,7 +28,7 @@ contract InterchainTokenDeployer is IInterchainTokenDeployer, Create3 { * @notice Deploys a new instance of the InterchainTokenProxy contract. * @param salt The salt used by Create3Deployer. * @param tokenId TokenId for the token. - * @param distributor Address of the distributor. + * @param minter Address of the minter. * @param name Name of the token. * @param symbol Symbol of the token. * @param decimals Decimals of the token. @@ -37,7 +37,7 @@ contract InterchainTokenDeployer is IInterchainTokenDeployer, Create3 { function deployInterchainToken( bytes32 salt, bytes32 tokenId, - address distributor, + address minter, string calldata name, string calldata symbol, uint8 decimals @@ -61,7 +61,7 @@ contract InterchainTokenDeployer is IInterchainTokenDeployer, Create3 { tokenAddress = _create3(bytecode, salt); if (tokenAddress.code.length == 0) revert TokenDeploymentFailed(); - IInterchainToken(tokenAddress).init(tokenId, distributor, name, symbol, decimals); + IInterchainToken(tokenAddress).init(tokenId, minter, name, symbol, decimals); } /** diff --git a/contracts/utils/RolesConstants.sol b/contracts/utils/RolesConstants.sol index 05add01a..1bbe690f 100644 --- a/contracts/utils/RolesConstants.sol +++ b/contracts/utils/RolesConstants.sol @@ -8,7 +8,7 @@ pragma solidity ^0.8.0; */ contract RolesConstants { enum Roles { - DISTRIBUTOR, + MINTER, OPERATOR, FLOW_LIMITER } diff --git a/test/InterchainToken.js b/test/InterchainToken.js index 055bff15..044b0c76 100644 --- a/test/InterchainToken.js +++ b/test/InterchainToken.js @@ -47,12 +47,12 @@ describe('InterchainToken', () => { const implementation = await getContractAt('InterchainToken', implementationAddress, owner); const tokenId = getRandomBytes32(); - const distributor = owner.address; + const minter = owner.address; const tokenName = 'name'; const tokenSymbol = 'symbol'; const tokenDecimals = 7; await expectRevert( - (gasOptions) => implementation.init(tokenId, distributor, tokenName, tokenSymbol, tokenDecimals, gasOptions), + (gasOptions) => implementation.init(tokenId, minter, tokenName, tokenSymbol, tokenDecimals, gasOptions), implementation, 'AlreadyInitialized', ); @@ -71,10 +71,9 @@ describe('InterchainToken', () => { const implementation = await getContractAt('InterchainToken', implementationAddress, owner); const salt = getRandomBytes32(); - const distributor = owner.address; + const minter = owner.address; await expectRevert( - (gasOptions) => - interchainTokenDeployer.deployInterchainToken(salt, HashZero, distributor, name, symbol, decimals, gasOptions), + (gasOptions) => interchainTokenDeployer.deployInterchainToken(salt, HashZero, minter, name, symbol, decimals, gasOptions), implementation, 'TokenIdZero', ); @@ -86,9 +85,9 @@ describe('InterchainToken', () => { const salt = getRandomBytes32(); const tokenId = getRandomBytes32(); - const distributor = owner.address; + const minter = owner.address; await expectRevert( - (gasOptions) => interchainTokenDeployer.deployInterchainToken(salt, tokenId, distributor, '', symbol, decimals, gasOptions), + (gasOptions) => interchainTokenDeployer.deployInterchainToken(salt, tokenId, minter, '', symbol, decimals, gasOptions), implementation, 'TokenNameEmpty', ); diff --git a/test/InterchainTokenFactory.js b/test/InterchainTokenFactory.js index 4181a164..bb2f3c17 100644 --- a/test/InterchainTokenFactory.js +++ b/test/InterchainTokenFactory.js @@ -20,7 +20,7 @@ const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1; const LOCK_UNLOCK = 2; const MINT_BURN = 0; -const DISTRIBUTOR_ROLE = 0; +const MINTER_ROLE = 0; const OPERATOR_ROLE = 1; const FLOW_LIMITER_ROLE = 2; @@ -255,17 +255,17 @@ describe('InterchainTokenFactory', () => { describe('Interchain Token Factory', async () => { let tokenId; const mintAmount = 1234; - const distributor = new Wallet(getRandomBytes32()).address; + const minter = new Wallet(getRandomBytes32()).address; - const checkRoles = async (tokenManager, distributor) => { + const checkRoles = async (tokenManager, minter) => { const token = await getContractAt('InterchainToken', await tokenManager.tokenAddress(), wallet); - expect(await token.isDistributor(distributor)).to.be.true; - expect(await token.isDistributor(service.address)).to.be.true; + expect(await token.isMinter(minter)).to.be.true; + expect(await token.isMinter(service.address)).to.be.true; - expect(await tokenManager.isOperator(distributor)).to.be.true; + expect(await tokenManager.isOperator(minter)).to.be.true; expect(await tokenManager.isOperator(service.address)).to.be.true; - expect(await tokenManager.isFlowLimiter(distributor)).to.be.true; + expect(await tokenManager.isFlowLimiter(minter)).to.be.true; expect(await tokenManager.isFlowLimiter(service.address)).to.be.true; }; @@ -273,24 +273,24 @@ describe('InterchainTokenFactory', () => { const salt = keccak256('0x1234'); tokenId = await tokenFactory.interchainTokenId(wallet.address, salt); const tokenAddress = await tokenFactory.interchainTokenAddress(wallet.address, salt); - const params = defaultAbiCoder.encode(['bytes', 'address'], [distributor, tokenAddress]); + const params = defaultAbiCoder.encode(['bytes', 'address'], [minter, tokenAddress]); const tokenManager = await getContractAt('TokenManager', await service.tokenManagerAddress(tokenId), wallet); - await expect(tokenFactory.deployInterchainToken(salt, name, symbol, decimals, 0, distributor)) + await expect(tokenFactory.deployInterchainToken(salt, name, symbol, decimals, 0, minter)) .to.emit(service, 'InterchainTokenDeployed') - .withArgs(tokenId, tokenAddress, distributor, name, symbol, decimals) + .withArgs(tokenId, tokenAddress, minter, name, symbol, decimals) .and.to.emit(service, 'TokenManagerDeployed') .withArgs(tokenId, tokenManager.address, MINT_BURN, params); - await checkRoles(tokenManager, distributor); + await checkRoles(tokenManager, minter); }); - it('Should register a token if the mint amount is zero and distributor is the zero address', async () => { + it('Should register a token if the mint amount is zero and minter is the zero address', async () => { const salt = keccak256('0x123456'); tokenId = await tokenFactory.interchainTokenId(wallet.address, salt); const tokenAddress = await tokenFactory.interchainTokenAddress(wallet.address, salt); - const distributorBytes = new Uint8Array(); - const params = defaultAbiCoder.encode(['bytes', 'address'], [distributorBytes, tokenAddress]); + const minterBytes = new Uint8Array(); + const params = defaultAbiCoder.encode(['bytes', 'address'], [minterBytes, tokenAddress]); const tokenManager = await getContractAt('TokenManager', await service.tokenManagerAddress(tokenId), wallet); await expect(tokenFactory.deployInterchainToken(salt, name, symbol, decimals, 0, AddressZero)) @@ -302,7 +302,7 @@ describe('InterchainTokenFactory', () => { await checkRoles(tokenManager, AddressZero); }); - it('Should register a token if the mint amount is greater than zero and the distributor is the zero address', async () => { + it('Should register a token if the mint amount is greater than zero and the minter is the zero address', async () => { const salt = keccak256('0x12345678'); tokenId = await tokenFactory.interchainTokenId(wallet.address, salt); const tokenAddress = await tokenFactory.interchainTokenAddress(wallet.address, salt); @@ -326,7 +326,7 @@ describe('InterchainTokenFactory', () => { const tokenManager = await getContractAt('TokenManager', await service.tokenManagerAddress(tokenId), wallet); const token = await getContractAt('InterchainToken', tokenAddress, wallet); - await expect(tokenFactory.deployInterchainToken(salt, name, symbol, decimals, mintAmount, distributor)) + await expect(tokenFactory.deployInterchainToken(salt, name, symbol, decimals, mintAmount, minter)) .to.emit(service, 'InterchainTokenDeployed') .withArgs(tokenId, tokenAddress, tokenFactory.address, name, symbol, decimals) .and.to.emit(service, 'TokenManagerDeployed') @@ -334,29 +334,29 @@ describe('InterchainTokenFactory', () => { .and.to.emit(token, 'Transfer') .withArgs(AddressZero, tokenFactory.address, mintAmount) .and.to.emit(tokenManager, 'RolesAdded') - .withArgs(distributor, 1 << FLOW_LIMITER_ROLE) + .withArgs(minter, 1 << FLOW_LIMITER_ROLE) .and.to.emit(tokenManager, 'RolesAdded') - .withArgs(distributor, 1 << OPERATOR_ROLE) + .withArgs(minter, 1 << OPERATOR_ROLE) .and.to.emit(token, 'RolesAdded') - .withArgs(distributor, 1 << DISTRIBUTOR_ROLE) + .withArgs(minter, 1 << MINTER_ROLE) .and.to.emit(token, 'RolesRemoved') - .withArgs(tokenFactory.address, 1 << DISTRIBUTOR_ROLE) + .withArgs(tokenFactory.address, 1 << MINTER_ROLE) .and.to.emit(tokenManager, 'RolesRemoved') .withArgs(tokenFactory.address, 1 << OPERATOR_ROLE) .and.to.emit(tokenManager, 'RolesRemoved') .withArgs(tokenFactory.address, 1 << FLOW_LIMITER_ROLE); - await expect(tokenFactory.interchainTransfer(tokenId, '', distributor, mintAmount, 0)) + await expect(tokenFactory.interchainTransfer(tokenId, '', minter, mintAmount, 0)) .to.emit(token, 'Transfer') - .withArgs(tokenFactory.address, distributor, mintAmount); + .withArgs(tokenFactory.address, minter, mintAmount); expect(await token.balanceOf(tokenFactory.address)).to.equal(0); - expect(await token.balanceOf(distributor)).to.equal(mintAmount); + expect(await token.balanceOf(minter)).to.equal(mintAmount); - await checkRoles(tokenManager, distributor); + await checkRoles(tokenManager, minter); }); - it('Should initiate a remote interchain token deployment with the same distributor', async () => { + it('Should initiate a remote interchain token deployment with the same minter', async () => { const gasValue = 1234; const mintAmount = 5678; @@ -375,13 +375,13 @@ describe('InterchainTokenFactory', () => { .and.to.emit(token, 'Transfer') .withArgs(AddressZero, tokenFactory.address, mintAmount) .and.to.emit(token, 'RolesAdded') - .withArgs(wallet.address, 1 << DISTRIBUTOR_ROLE) + .withArgs(wallet.address, 1 << MINTER_ROLE) .and.to.emit(tokenManager, 'RolesAdded') .withArgs(wallet.address, 1 << OPERATOR_ROLE) .and.to.emit(tokenManager, 'RolesAdded') .withArgs(wallet.address, 1 << FLOW_LIMITER_ROLE) .and.to.emit(token, 'RolesRemoved') - .withArgs(tokenFactory.address, 1 << DISTRIBUTOR_ROLE) + .withArgs(tokenFactory.address, 1 << MINTER_ROLE) .and.to.emit(tokenManager, 'RolesRemoved') .withArgs(tokenFactory.address, 1 << OPERATOR_ROLE) .and.to.emit(tokenManager, 'RolesRemoved') @@ -400,7 +400,7 @@ describe('InterchainTokenFactory', () => { value: gasValue, }), tokenFactory, - 'NotDistributor', + 'NotMinter', [otherWallet.address], ); @@ -429,7 +429,7 @@ describe('InterchainTokenFactory', () => { .withArgs(service.address, destinationChain, service.address, keccak256(payload), payload); }); - it('Should initiate a remote interchain token deployment without the same distributor', async () => { + it('Should initiate a remote interchain token deployment without the same minter', async () => { const gasValue = 1234; const salt = keccak256('0x1245'); @@ -447,13 +447,13 @@ describe('InterchainTokenFactory', () => { .and.to.emit(token, 'Transfer') .withArgs(AddressZero, tokenFactory.address, mintAmount) .and.to.emit(token, 'RolesAdded') - .withArgs(wallet.address, 1 << DISTRIBUTOR_ROLE) + .withArgs(wallet.address, 1 << MINTER_ROLE) .and.to.emit(tokenManager, 'RolesAdded') .withArgs(wallet.address, 1 << OPERATOR_ROLE) .and.to.emit(tokenManager, 'RolesAdded') .withArgs(wallet.address, 1 << FLOW_LIMITER_ROLE) .and.to.emit(token, 'RolesRemoved') - .withArgs(tokenFactory.address, 1 << DISTRIBUTOR_ROLE) + .withArgs(tokenFactory.address, 1 << MINTER_ROLE) .and.to.emit(tokenManager, 'RolesRemoved') .withArgs(tokenFactory.address, 1 << OPERATOR_ROLE) .and.to.emit(tokenManager, 'RolesRemoved') diff --git a/test/InterchainTokenService.js b/test/InterchainTokenService.js index e00ad467..06b8ac48 100644 --- a/test/InterchainTokenService.js +++ b/test/InterchainTokenService.js @@ -25,7 +25,7 @@ const MINT_BURN_FROM = 1; const LOCK_UNLOCK = 2; const LOCK_UNLOCK_FEE_ON_TRANSFER = 3; -// const DISTRIBUTOR_ROLE = 0; +// const MINTER_ROLE = 0; const OPERATOR_ROLE = 1; const FLOW_LIMITER_ROLE = 2; @@ -142,7 +142,7 @@ describe('Interchain Token Service', () => { await (await token.mint(wallet.address, mintAmount)).wait(); } - await (await token.transferDistributorship(service.address)).wait(); + await (await token.transferMinterRole(service.address)).wait(); const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]); await (await service.deployTokenManager(salt, '', type, params, 0)).wait(); @@ -586,8 +586,8 @@ describe('Interchain Token Service', () => { expect(await tokenManager.isFlowLimiter(service.address)).to.be.true; const token = await getContractAt('InterchainToken', tokenAddress, wallet); - expect(await token.isDistributor(wallet.address)).to.be.true; - expect(await token.isDistributor(service.address)).to.be.true; + expect(await token.isMinter(wallet.address)).to.be.true; + expect(await token.isMinter(service.address)).to.be.true; }); it('Should revert when registering an interchain token when service is paused', async () => { @@ -638,7 +638,7 @@ describe('Interchain Token Service', () => { const tokenName = 'Token Name'; const tokenSymbol = 'TN'; const tokenDecimals = 13; - const distributor = '0x12345678'; + const minter = '0x12345678'; const gasValue = 1234; let salt; @@ -652,19 +652,19 @@ describe('Interchain Token Service', () => { const tokenId = await service.interchainTokenId(wallet.address, salt); const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes'], - [MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor], + [MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, minter], ); await expect( reportGas( - service.deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, distributor, gasValue, { + service.deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, minter, gasValue, { value: gasValue, }), 'Send deployInterchainToken to remote chain', ), ) .to.emit(service, 'InterchainTokenDeploymentStarted') - .withArgs(tokenId, tokenName, tokenSymbol, tokenDecimals, distributor, destinationChain) + .withArgs(tokenId, tokenName, tokenSymbol, tokenDecimals, minter, destinationChain) .and.to.emit(gasService, 'NativeGasPaidForContractCall') .withArgs(service.address, destinationChain, service.address, keccak256(payload), gasValue, wallet.address) .and.to.emit(gateway, 'ContractCall') @@ -680,7 +680,7 @@ describe('Interchain Token Service', () => { await expectRevert( (gasOptions) => - service.deployInterchainToken(salt, 'untrusted chain', tokenName, tokenSymbol, tokenDecimals, distributor, gasValue, { + service.deployInterchainToken(salt, 'untrusted chain', tokenName, tokenSymbol, tokenDecimals, minter, gasValue, { ...gasOptions, value: gasValue, }), @@ -697,7 +697,7 @@ describe('Interchain Token Service', () => { await expectRevert( (gasOptions) => - service.deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, distributor, gasValue, { + service.deployInterchainToken(salt, destinationChain, tokenName, tokenSymbol, tokenDecimals, minter, gasValue, { ...gasOptions, value: gasValue, }), @@ -722,11 +722,11 @@ describe('Interchain Token Service', () => { it('Should revert on receiving a remote interchain token deployment if not approved by the gateway', async () => { const tokenId = getRandomBytes32(); - const distributor = wallet.address; + const minter = wallet.address; const commandId = getRandomBytes32(); const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes'], - [MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor], + [MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, minter], ); await expectRevert( @@ -738,7 +738,7 @@ describe('Interchain Token Service', () => { it('Should be able to receive a remote interchain token deployment with a mint/burn token manager', async () => { const tokenId = getRandomBytes32(); - const distributor = wallet.address; + const minter = wallet.address; const operator = wallet.address; const tokenManagerAddress = await service.tokenManagerAddress(tokenId); @@ -746,13 +746,13 @@ describe('Interchain Token Service', () => { const params = defaultAbiCoder.encode(['bytes', 'address'], [operator, tokenAddress]); const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes'], - [MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor], + [MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, minter], ); const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload); await expect(reportGas(service.execute(commandId, sourceChain, sourceAddress, payload), 'Receive GMP DEPLOY_INTERCHAIN_TOKEN')) .to.emit(service, 'InterchainTokenDeployed') - .withArgs(tokenId, tokenAddress, distributor, tokenName, tokenSymbol, tokenDecimals) + .withArgs(tokenId, tokenAddress, minter, tokenName, tokenSymbol, tokenDecimals) .and.to.emit(service, 'TokenManagerDeployed') .withArgs(tokenId, tokenManagerAddress, MINT_BURN, params); @@ -762,16 +762,16 @@ describe('Interchain Token Service', () => { expect(await tokenManager.hasRole(operator, OPERATOR_ROLE)).to.be.true; }); - it('Should be able to receive a remote interchain token deployment with a mint/burn token manager with empty distributor and operator', async () => { + it('Should be able to receive a remote interchain token deployment with a mint/burn token manager with empty minter and operator', async () => { const tokenId = getRandomBytes32(); const tokenManagerAddress = await service.tokenManagerAddress(tokenId); - const distributor = '0x'; + const minter = '0x'; const operator = '0x'; const tokenAddress = await service.interchainTokenAddress(tokenId); const params = defaultAbiCoder.encode(['bytes', 'address'], [operator, tokenAddress]); const payload = defaultAbiCoder.encode( ['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes', 'bytes'], - [MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, distributor, operator], + [MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, tokenName, tokenSymbol, tokenDecimals, minter, operator], ); const commandId = await approveContractCall(gateway, sourceChain, sourceAddress, service.address, payload); diff --git a/test/InterchainTokenServiceFullFlow.js b/test/InterchainTokenServiceFullFlow.js index a2e37e62..62e40e4b 100644 --- a/test/InterchainTokenServiceFullFlow.js +++ b/test/InterchainTokenServiceFullFlow.js @@ -19,7 +19,7 @@ const MESSAGE_TYPE_INTERCHAIN_TRANSFER = 0; const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1; const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 2; -const DISTRIBUTOR_ROLE = 0; +const MINTER_ROLE = 0; const MINT_BURN = 0; const LOCK_UNLOCK = 2; @@ -321,28 +321,28 @@ describe('Interchain Token Service Full Flow', () => { }); /** - * Change the distributor/minter to another address + * Change the minter/minter to another address */ - it('Should be able to change the token distributor', async () => { + it('Should be able to change the token minter', async () => { const newAddress = new Wallet(getRandomBytes32()).address; const amount = 1234; await expect(token.mint(newAddress, amount)).to.emit(token, 'Transfer').withArgs(AddressZero, newAddress, amount); await expect(token.burn(newAddress, amount)).to.emit(token, 'Transfer').withArgs(newAddress, AddressZero, amount); - await expect(token.transferDistributorship(newAddress)) + await expect(token.transferMinterRole(newAddress)) .to.emit(token, 'RolesRemoved') - .withArgs(wallet.address, 1 << DISTRIBUTOR_ROLE) + .withArgs(wallet.address, 1 << MINTER_ROLE) .to.emit(token, 'RolesAdded') - .withArgs(newAddress, 1 << DISTRIBUTOR_ROLE); + .withArgs(newAddress, 1 << MINTER_ROLE); await expectRevert((gasOptions) => token.mint(newAddress, amount, gasOptions), token, 'MissingRole', [ wallet.address, - DISTRIBUTOR_ROLE, + MINTER_ROLE, ]); await expectRevert((gasOptions) => token.burn(newAddress, amount, gasOptions), token, 'MissingRole', [ wallet.address, - DISTRIBUTOR_ROLE, + MINTER_ROLE, ]); }); }); @@ -351,7 +351,7 @@ describe('Interchain Token Service Full Flow', () => { * This test creates a token link between pre-existing tokens by giving mint/burn permission to ITS. * - Deploy a normal mint/burn ERC20 registered with an owner * - Deploy a mint/burn token manager for the token on all chains - * - Transfer mint/burn permission (distributor role) to ITS + * - Transfer mint/burn permission (minter role) to ITS * - Transfer tokens via ITS between chains */ describe('Pre-existing Token as Mint/Burn', () => { @@ -411,28 +411,28 @@ describe('Interchain Token Service Full Flow', () => { }); /** - * Transfer the distributor to ITS on all chains to allow it to mint/burn + * Transfer the minter to ITS on all chains to allow it to mint/burn */ - it('Should be able to change the token distributor', async () => { + it('Should be able to change the token minter', async () => { const newAddress = new Wallet(getRandomBytes32()).address; const amount = 1234; await expect(token.mint(newAddress, amount)).to.emit(token, 'Transfer').withArgs(AddressZero, newAddress, amount); await expect(token.burn(newAddress, amount)).to.emit(token, 'Transfer').withArgs(newAddress, AddressZero, amount); - await expect(token.transferDistributorship(service.address)) + await expect(token.transferMinterRole(service.address)) .to.emit(token, 'RolesRemoved') - .withArgs(wallet.address, 1 << DISTRIBUTOR_ROLE) + .withArgs(wallet.address, 1 << MINTER_ROLE) .to.emit(token, 'RolesAdded') - .withArgs(service.address, 1 << DISTRIBUTOR_ROLE); + .withArgs(service.address, 1 << MINTER_ROLE); await expectRevert((gasOptions) => token.mint(newAddress, amount, gasOptions), token, 'MissingRole', [ wallet.address, - DISTRIBUTOR_ROLE, + MINTER_ROLE, ]); await expectRevert((gasOptions) => token.burn(newAddress, amount, gasOptions), token, 'MissingRole', [ wallet.address, - DISTRIBUTOR_ROLE, + MINTER_ROLE, ]); }); diff --git a/test/UtilsTest.js b/test/UtilsTest.js index 1aedec98..52b6fb29 100644 --- a/test/UtilsTest.js +++ b/test/UtilsTest.js @@ -96,72 +96,72 @@ describe('Operatable', () => { describe('Distributable', () => { let test; - let distributorRole; + let minterRole; before(async () => { test = await deployContract(ownerWallet, 'TestDistributable', [ownerWallet.address]); - distributorRole = await test.distributorRole(); + minterRole = await test.minterRole(); }); - it('Should be able to run the onlyDistributor function as the distributor', async () => { + it('Should be able to run the onlyMinter function as the minter', async () => { await (await test.testDistributable()).wait(); expect(await test.nonce()).to.equal(1); }); - it('Should not be able to run the onlyDistributor function as not the distributor', async () => { + it('Should not be able to run the onlyMinter function as not the minter', async () => { await expectRevert((gasOptions) => test.connect(otherWallet).testDistributable(gasOptions), test, 'MissingRole', [ otherWallet.address, - distributorRole, + minterRole, ]); }); - it('Should be able to change the distributor only as the distributor', async () => { - expect(await test.hasRole(ownerWallet.address, distributorRole)).to.be.true; + it('Should be able to change the minter only as the minter', async () => { + expect(await test.hasRole(ownerWallet.address, minterRole)).to.be.true; - await expect(test.transferDistributorship(otherWallet.address)) + await expect(test.transferMinterRole(otherWallet.address)) .to.emit(test, 'RolesRemoved') - .withArgs(ownerWallet.address, 1 << distributorRole) + .withArgs(ownerWallet.address, 1 << minterRole) .to.emit(test, 'RolesAdded') - .withArgs(otherWallet.address, 1 << distributorRole); + .withArgs(otherWallet.address, 1 << minterRole); - expect(await test.hasRole(otherWallet.address, distributorRole)).to.be.true; + expect(await test.hasRole(otherWallet.address, minterRole)).to.be.true; - await expectRevert((gasOptions) => test.transferDistributorship(otherWallet.address, gasOptions), test, 'MissingRole', [ + await expectRevert((gasOptions) => test.transferMinterRole(otherWallet.address, gasOptions), test, 'MissingRole', [ ownerWallet.address, - distributorRole, + minterRole, ]); }); - it('Should be able to propose a new distributor only as distributor', async () => { - expect(await test.hasRole(otherWallet.address, distributorRole)).to.be.true; + it('Should be able to propose a new minter only as minter', async () => { + expect(await test.hasRole(otherWallet.address, minterRole)).to.be.true; await expectRevert( - (gasOptions) => test.connect(ownerWallet).proposeDistributorship(ownerWallet.address, gasOptions), + (gasOptions) => test.connect(ownerWallet).proposeMinterRole(ownerWallet.address, gasOptions), test, 'MissingRole', - [ownerWallet.address, distributorRole], + [ownerWallet.address, minterRole], ); - await expect(test.connect(otherWallet).proposeDistributorship(ownerWallet.address)) + await expect(test.connect(otherWallet).proposeMinterRole(ownerWallet.address)) .to.emit(test, 'RolesProposed') - .withArgs(otherWallet.address, ownerWallet.address, 1 << distributorRole); + .withArgs(otherWallet.address, ownerWallet.address, 1 << minterRole); }); - it('Should be able to accept distributorship only as the proposed distributor', async () => { - expect(await test.hasRole(otherWallet.address, distributorRole)).to.be.true; + it('Should be able to accept minterRole only as the proposed minter', async () => { + expect(await test.hasRole(otherWallet.address, minterRole)).to.be.true; await expectRevert( - (gasOptions) => test.connect(otherWallet).acceptDistributorship(otherWallet.address, gasOptions), + (gasOptions) => test.connect(otherWallet).acceptMinterRole(otherWallet.address, gasOptions), test, 'InvalidProposedRoles', ); - await expect(test.connect(ownerWallet).acceptDistributorship(otherWallet.address)) + await expect(test.connect(ownerWallet).acceptMinterRole(otherWallet.address)) .to.emit(test, 'RolesRemoved') - .withArgs(otherWallet.address, 1 << distributorRole) + .withArgs(otherWallet.address, 1 << minterRole) .to.emit(test, 'RolesAdded') - .withArgs(ownerWallet.address, 1 << distributorRole); + .withArgs(ownerWallet.address, 1 << minterRole); }); }); @@ -262,7 +262,7 @@ describe('InterchainTokenDeployer', () => { const name = 'tokenName'; const symbol = 'tokenSymbol'; const decimals = 18; - const DISTRIBUTOR_ROLE = 0; + const MINTER_ROLE = 0; before(async () => { interchainToken = await deployContract(ownerWallet, 'InterchainToken', [service]); @@ -286,15 +286,15 @@ describe('InterchainTokenDeployer', () => { await expect(interchainTokenDeployer.deployInterchainToken(salt, tokenId, ownerWallet.address, name, symbol, decimals)) .to.emit(token, 'RolesAdded') - .withArgs(service, 1 << DISTRIBUTOR_ROLE) + .withArgs(service, 1 << MINTER_ROLE) .and.to.emit(token, 'RolesAdded') - .withArgs(ownerWallet.address, 1 << DISTRIBUTOR_ROLE); + .withArgs(ownerWallet.address, 1 << MINTER_ROLE); expect(await token.name()).to.equal(name); expect(await token.symbol()).to.equal(symbol); expect(await token.decimals()).to.equal(decimals); - expect(await token.hasRole(service, DISTRIBUTOR_ROLE)).to.be.true; - expect(await token.hasRole(ownerWallet.address, DISTRIBUTOR_ROLE)).to.be.true; + expect(await token.hasRole(service, MINTER_ROLE)).to.be.true; + expect(await token.hasRole(ownerWallet.address, MINTER_ROLE)).to.be.true; expect(await token.interchainTokenId()).to.equal(tokenId); expect(await token.interchainTokenService()).to.equal(service); From 1cce1a4dd03ed7ec48b34529e362036536545d63 Mon Sep 17 00:00:00 2001 From: Kiryl Yermakou Date: Tue, 5 Dec 2023 11:41:13 -0500 Subject: [PATCH 2/5] refactor(ITS): Distributable -> Minter --- contracts/interchain-token/InterchainToken.sol | 6 +++--- contracts/interfaces/IInterchainToken.sol | 6 +++--- contracts/interfaces/{IDistributable.sol => IMinter.sol} | 4 ++-- contracts/test/TestBaseInterchainToken.sol | 4 ++-- contracts/test/TestFeeOnTransferToken.sol | 4 ++-- contracts/test/TestMintableBurnableERC20.sol | 4 ++-- contracts/test/utils/TestDistributable.sol | 6 +++--- contracts/utils/{Distributable.sol => Minter.sol} | 6 +++--- test/UtilsTest.js | 8 ++++---- 9 files changed, 24 insertions(+), 24 deletions(-) rename contracts/interfaces/{IDistributable.sol => IMinter.sol} (94%) rename contracts/utils/{Distributable.sol => Minter.sol} (92%) diff --git a/contracts/interchain-token/InterchainToken.sol b/contracts/interchain-token/InterchainToken.sol index e966529b..c3926c29 100644 --- a/contracts/interchain-token/InterchainToken.sol +++ b/contracts/interchain-token/InterchainToken.sol @@ -8,14 +8,14 @@ import { IInterchainToken } from '../interfaces/IInterchainToken.sol'; import { BaseInterchainToken } from './BaseInterchainToken.sol'; import { ERC20Permit } from './ERC20Permit.sol'; -import { Distributable } from '../utils/Distributable.sol'; +import { Minter } from '../utils/Minter.sol'; /** * @title InterchainToken * @notice This contract implements an interchain token which extends InterchainToken functionality. - * @dev This contract also inherits Distributable and Implementation logic. + * @dev This contract also inherits Minter and Implementation logic. */ -contract InterchainToken is BaseInterchainToken, ERC20Permit, Distributable, IInterchainToken { +contract InterchainToken is BaseInterchainToken, ERC20Permit, Minter, IInterchainToken { using AddressBytes for bytes; string public name; diff --git a/contracts/interfaces/IInterchainToken.sol b/contracts/interfaces/IInterchainToken.sol index ddd760e7..ea825627 100644 --- a/contracts/interfaces/IInterchainToken.sol +++ b/contracts/interfaces/IInterchainToken.sol @@ -3,15 +3,15 @@ pragma solidity ^0.8.0; import { IInterchainTokenStandard } from './IInterchainTokenStandard.sol'; -import { IDistributable } from './IDistributable.sol'; +import { IMinter } from './IMinter.sol'; import { IERC20MintableBurnable } from './IERC20MintableBurnable.sol'; import { IERC20Named } from './IERC20Named.sol'; /** * @title IInterchainToken interface - * @dev Extends IInterchainTokenStandard and IDistributable. + * @dev Extends IInterchainTokenStandard and IMinter. */ -interface IInterchainToken is IInterchainTokenStandard, IDistributable, IERC20MintableBurnable, IERC20Named { +interface IInterchainToken is IInterchainTokenStandard, IMinter, IERC20MintableBurnable, IERC20Named { error InterchainTokenServiceAddressZero(); error TokenIdZero(); error TokenNameEmpty(); diff --git a/contracts/interfaces/IDistributable.sol b/contracts/interfaces/IMinter.sol similarity index 94% rename from contracts/interfaces/IDistributable.sol rename to contracts/interfaces/IMinter.sol index 3456e674..78f96e66 100644 --- a/contracts/interfaces/IDistributable.sol +++ b/contracts/interfaces/IMinter.sol @@ -5,11 +5,11 @@ pragma solidity ^0.8.0; import { IRolesBase } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IRolesBase.sol'; /** - * @title IDistributable Interface + * @title IMinter Interface * @notice An interface for a contract module which provides a basic access control mechanism, where * there is an account (a minter) that can be granted exclusive access to specific functions. */ -interface IDistributable is IRolesBase { +interface IMinter is IRolesBase { /** * @notice Change the minter of the contract. * @dev Can only be called by the current minter. diff --git a/contracts/test/TestBaseInterchainToken.sol b/contracts/test/TestBaseInterchainToken.sol index 5bdaa1de..6e92ee2e 100644 --- a/contracts/test/TestBaseInterchainToken.sol +++ b/contracts/test/TestBaseInterchainToken.sol @@ -3,10 +3,10 @@ pragma solidity ^0.8.0; import { BaseInterchainToken } from '../interchain-token/BaseInterchainToken.sol'; -import { Distributable } from '../utils/Distributable.sol'; +import { Minter } from '../utils/Minter.sol'; import { IERC20MintableBurnable } from '../interfaces/IERC20MintableBurnable.sol'; -contract TestBaseInterchainToken is BaseInterchainToken, Distributable, IERC20MintableBurnable { +contract TestBaseInterchainToken is BaseInterchainToken, Minter, IERC20MintableBurnable { address internal service; bytes32 internal tokenId; bool internal tokenManagerRequiresApproval_ = true; diff --git a/contracts/test/TestFeeOnTransferToken.sol b/contracts/test/TestFeeOnTransferToken.sol index f975c663..2ff5b22c 100644 --- a/contracts/test/TestFeeOnTransferToken.sol +++ b/contracts/test/TestFeeOnTransferToken.sol @@ -3,10 +3,10 @@ pragma solidity ^0.8.0; import { BaseInterchainToken } from '../interchain-token/BaseInterchainToken.sol'; -import { Distributable } from '../utils/Distributable.sol'; +import { Minter } from '../utils/Minter.sol'; import { IERC20MintableBurnable } from '../interfaces/IERC20MintableBurnable.sol'; -contract TestFeeOnTransferToken is BaseInterchainToken, Distributable, IERC20MintableBurnable { +contract TestFeeOnTransferToken is BaseInterchainToken, Minter, IERC20MintableBurnable { address public immutable service; bytes32 public tokenId; bool internal tokenManagerRequiresApproval_ = true; diff --git a/contracts/test/TestMintableBurnableERC20.sol b/contracts/test/TestMintableBurnableERC20.sol index 6a26211e..52e6c1cd 100644 --- a/contracts/test/TestMintableBurnableERC20.sol +++ b/contracts/test/TestMintableBurnableERC20.sol @@ -3,10 +3,10 @@ pragma solidity ^0.8.0; import { ERC20 } from '../interchain-token/ERC20.sol'; -import { Distributable } from '../utils/Distributable.sol'; +import { Minter } from '../utils/Minter.sol'; import { IERC20MintableBurnable } from '../interfaces/IERC20MintableBurnable.sol'; -contract TestMintableBurnableERC20 is ERC20, Distributable, IERC20MintableBurnable { +contract TestMintableBurnableERC20 is ERC20, Minter, IERC20MintableBurnable { string public name; string public symbol; uint8 public decimals; diff --git a/contracts/test/utils/TestDistributable.sol b/contracts/test/utils/TestDistributable.sol index 4b3c22c7..151378b6 100644 --- a/contracts/test/utils/TestDistributable.sol +++ b/contracts/test/utils/TestDistributable.sol @@ -2,16 +2,16 @@ pragma solidity ^0.8.0; -import { Distributable } from '../../utils/Distributable.sol'; +import { Minter } from '../../utils/Minter.sol'; -contract TestDistributable is Distributable { +contract TestMinter is Minter { uint256 public nonce; constructor(address minter) { _addMinter(minter); } - function testDistributable() external onlyRole(uint8(Roles.MINTER)) { + function testMinter() external onlyRole(uint8(Roles.MINTER)) { nonce++; } diff --git a/contracts/utils/Distributable.sol b/contracts/utils/Minter.sol similarity index 92% rename from contracts/utils/Distributable.sol rename to contracts/utils/Minter.sol index 73bcc9af..fd7788f6 100644 --- a/contracts/utils/Distributable.sol +++ b/contracts/utils/Minter.sol @@ -2,19 +2,19 @@ pragma solidity ^0.8.0; -import { IDistributable } from '../interfaces/IDistributable.sol'; +import { IMinter } from '../interfaces/IMinter.sol'; import { RolesBase } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/RolesBase.sol'; import { RolesConstants } from './RolesConstants.sol'; /** - * @title Distributable Contract + * @title Minter Contract * @notice A contract module which provides a basic access control mechanism, where * there is an account (a minter) that can be granted exclusive access to * specific functions. * @dev This module is used through inheritance. */ -contract Distributable is IDistributable, RolesBase, RolesConstants { +contract Minter is IMinter, RolesBase, RolesConstants { /** * @notice Internal function that stores the new minter address in the correct storage slot. * @param minter_ The address of the new minter. diff --git a/test/UtilsTest.js b/test/UtilsTest.js index 52b6fb29..276fe27d 100644 --- a/test/UtilsTest.js +++ b/test/UtilsTest.js @@ -94,23 +94,23 @@ describe('Operatable', () => { }); }); -describe('Distributable', () => { +describe('Minter', () => { let test; let minterRole; before(async () => { - test = await deployContract(ownerWallet, 'TestDistributable', [ownerWallet.address]); + test = await deployContract(ownerWallet, 'TestMinter', [ownerWallet.address]); minterRole = await test.minterRole(); }); it('Should be able to run the onlyMinter function as the minter', async () => { - await (await test.testDistributable()).wait(); + await (await test.testMinter()).wait(); expect(await test.nonce()).to.equal(1); }); it('Should not be able to run the onlyMinter function as not the minter', async () => { - await expectRevert((gasOptions) => test.connect(otherWallet).testDistributable(gasOptions), test, 'MissingRole', [ + await expectRevert((gasOptions) => test.connect(otherWallet).testMinter(gasOptions), test, 'MissingRole', [ otherWallet.address, minterRole, ]); From 20f5f867481af0b4d0f76c16090caeac5b14c73f Mon Sep 17 00:00:00 2001 From: Kiryl Yermakou Date: Tue, 5 Dec 2023 11:42:05 -0500 Subject: [PATCH 3/5] refactor(ITS): Distributable -> Minter --- contracts/test/utils/{TestDistributable.sol => TestMinter.sol} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename contracts/test/utils/{TestDistributable.sol => TestMinter.sol} (100%) diff --git a/contracts/test/utils/TestDistributable.sol b/contracts/test/utils/TestMinter.sol similarity index 100% rename from contracts/test/utils/TestDistributable.sol rename to contracts/test/utils/TestMinter.sol From fc615346e312d2e6df6b76a7657439037e28ad23 Mon Sep 17 00:00:00 2001 From: Kiryl Yermakou Date: Tue, 5 Dec 2023 11:48:04 -0500 Subject: [PATCH 4/5] fix(Factory): revert bytes initializing --- contracts/InterchainTokenFactory.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/InterchainTokenFactory.sol b/contracts/InterchainTokenFactory.sol index 0a376cfc..bab56a2a 100644 --- a/contracts/InterchainTokenFactory.sol +++ b/contracts/InterchainTokenFactory.sol @@ -132,7 +132,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M ) external payable { address sender = msg.sender; salt = interchainTokenSalt(chainNameHash, sender, salt); - bytes memory minterBytes; + bytes memory minterBytes = new bytes(0); if (initialSupply > 0) { minterBytes = address(this).toBytes(); @@ -179,7 +179,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M string memory tokenName; string memory tokenSymbol; uint8 tokenDecimals; - bytes memory minter_; + bytes memory minter_ = new bytes(0); { bytes32 chainNameHash_; From a00b9a464397dbfe5c6264c802745efda77f35da Mon Sep 17 00:00:00 2001 From: Kiryl Yermakou Date: Tue, 5 Dec 2023 12:54:02 -0500 Subject: [PATCH 5/5] refactor(ITS): Operatable -> Operator --- contracts/InterchainTokenFactory.sol | 2 +- contracts/InterchainTokenService.sol | 4 ++-- contracts/interfaces/IMinter.sol | 6 +++--- .../{IOperatable.sol => IOperator.sol} | 4 ++-- contracts/interfaces/ITokenManager.sol | 4 ++-- .../{TestOperatable.sol => TestOperator.sol} | 4 ++-- contracts/token-manager/TokenManager.sol | 4 ++-- contracts/utils/Minter.sol | 6 +++--- contracts/utils/{Operatable.sol => Operator.sol} | 6 +++--- test/InterchainTokenService.js | 2 +- test/InterchainTokenServiceFullFlow.js | 4 ++-- test/UtilsTest.js | 16 ++++++++-------- 12 files changed, 31 insertions(+), 31 deletions(-) rename contracts/interfaces/{IOperatable.sol => IOperator.sol} (95%) rename contracts/test/utils/{TestOperatable.sol => TestOperator.sol} (79%) rename contracts/utils/{Operatable.sol => Operator.sol} (93%) diff --git a/contracts/InterchainTokenFactory.sol b/contracts/InterchainTokenFactory.sol index bab56a2a..3700e78b 100644 --- a/contracts/InterchainTokenFactory.sol +++ b/contracts/InterchainTokenFactory.sol @@ -150,7 +150,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M _setDeployerTokenBalance(tokenId, sender, initialSupply); token.mint(address(this), initialSupply); - token.transferMinterRole(minter); + token.transferMintership(minter); tokenManager.removeFlowLimiter(address(this)); diff --git a/contracts/InterchainTokenService.sol b/contracts/InterchainTokenService.sol index c1431615..3fef5258 100644 --- a/contracts/InterchainTokenService.sol +++ b/contracts/InterchainTokenService.sol @@ -24,7 +24,7 @@ import { IInterchainTokenExecutable } from './interfaces/IInterchainTokenExecuta import { IInterchainTokenExpressExecutable } from './interfaces/IInterchainTokenExpressExecutable.sol'; import { ITokenManager } from './interfaces/ITokenManager.sol'; -import { Operatable } from './utils/Operatable.sol'; +import { Operator } from './utils/Operator.sol'; /** * @title The Interchain Token Service @@ -35,7 +35,7 @@ import { Operatable } from './utils/Operatable.sol'; */ contract InterchainTokenService is Upgradable, - Operatable, + Operator, Pausable, Multicall, Create3Address, diff --git a/contracts/interfaces/IMinter.sol b/contracts/interfaces/IMinter.sol index 78f96e66..7a11dfb9 100644 --- a/contracts/interfaces/IMinter.sol +++ b/contracts/interfaces/IMinter.sol @@ -15,21 +15,21 @@ interface IMinter is IRolesBase { * @dev Can only be called by the current minter. * @param minter_ The address of the new minter. */ - function transferMinterRole(address minter_) external; + function transferMintership(address minter_) external; /** * @notice Proposed a change of the minter of the contract. * @dev Can only be called by the current minter. * @param minter_ The address of the new minter. */ - function proposeMinterRole(address minter_) external; + function proposeMintership(address minter_) external; /** * @notice Accept a change of the minter of the contract. * @dev Can only be called by the proposed minter. * @param fromMinter The previous minter. */ - function acceptMinterRole(address fromMinter) external; + function acceptMintership(address fromMinter) external; /** * @notice Query if an address is a minter diff --git a/contracts/interfaces/IOperatable.sol b/contracts/interfaces/IOperator.sol similarity index 95% rename from contracts/interfaces/IOperatable.sol rename to contracts/interfaces/IOperator.sol index 6281ac1e..64ce030b 100644 --- a/contracts/interfaces/IOperatable.sol +++ b/contracts/interfaces/IOperator.sol @@ -5,11 +5,11 @@ pragma solidity ^0.8.0; import { IRolesBase } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IRolesBase.sol'; /** - * @title IOperatable Interface + * @title IOperator Interface * @notice An interface for a contract module which provides a basic access control mechanism, where * there is an account (a operator) that can be granted exclusive access to specific functions. */ -interface IOperatable is IRolesBase { +interface IOperator is IRolesBase { /** * @notice Change the operator of the contract. * @dev Can only be called by the current operator. diff --git a/contracts/interfaces/ITokenManager.sol b/contracts/interfaces/ITokenManager.sol index e09d37d4..435570a9 100644 --- a/contracts/interfaces/ITokenManager.sol +++ b/contracts/interfaces/ITokenManager.sol @@ -5,14 +5,14 @@ pragma solidity ^0.8.0; import { IImplementation } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IImplementation.sol'; import { IBaseTokenManager } from './IBaseTokenManager.sol'; -import { IOperatable } from './IOperatable.sol'; +import { IOperator } from './IOperator.sol'; import { IFlowLimit } from './IFlowLimit.sol'; /** * @title ITokenManager Interface * @notice This contract is responsible for managing tokens, such as setting locking token balances, or setting flow limits, for interchain transfers. */ -interface ITokenManager is IBaseTokenManager, IOperatable, IFlowLimit, IImplementation { +interface ITokenManager is IBaseTokenManager, IOperator, IFlowLimit, IImplementation { error TokenLinkerZeroAddress(); error NotService(address caller); error TakeTokenFailed(); diff --git a/contracts/test/utils/TestOperatable.sol b/contracts/test/utils/TestOperator.sol similarity index 79% rename from contracts/test/utils/TestOperatable.sol rename to contracts/test/utils/TestOperator.sol index 5781711b..fa8ba84e 100644 --- a/contracts/test/utils/TestOperatable.sol +++ b/contracts/test/utils/TestOperator.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.0; -import { Operatable } from '../../utils/Operatable.sol'; +import { Operator } from '../../utils/Operator.sol'; -contract TestOperatable is Operatable { +contract TestOperator is Operator { uint256 public nonce; constructor(address operator) { diff --git a/contracts/token-manager/TokenManager.sol b/contracts/token-manager/TokenManager.sol index 3a6744af..c2584230 100644 --- a/contracts/token-manager/TokenManager.sol +++ b/contracts/token-manager/TokenManager.sol @@ -11,14 +11,14 @@ import { SafeTokenCall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts import { ITokenManager } from '../interfaces/ITokenManager.sol'; import { IInterchainTokenService } from '../interfaces/IInterchainTokenService.sol'; -import { Operatable } from '../utils/Operatable.sol'; +import { Operator } from '../utils/Operator.sol'; import { FlowLimit } from '../utils/FlowLimit.sol'; /** * @title TokenManager * @notice This contract is responsible for managing tokens, such as setting locking token balances, or setting flow limits, for interchain transfers. */ -contract TokenManager is ITokenManager, Operatable, FlowLimit, Implementation { +contract TokenManager is ITokenManager, Operator, FlowLimit, Implementation { using AddressBytes for bytes; using SafeTokenCall for IERC20; diff --git a/contracts/utils/Minter.sol b/contracts/utils/Minter.sol index fd7788f6..742d1d12 100644 --- a/contracts/utils/Minter.sol +++ b/contracts/utils/Minter.sol @@ -28,7 +28,7 @@ contract Minter is IMinter, RolesBase, RolesConstants { * @dev Can only be called by the current minter. * @param minter_ The address of the new minter. */ - function transferMinterRole(address minter_) external onlyRole(uint8(Roles.MINTER)) { + function transferMintership(address minter_) external onlyRole(uint8(Roles.MINTER)) { _transferRole(msg.sender, minter_, uint8(Roles.MINTER)); } @@ -37,7 +37,7 @@ contract Minter is IMinter, RolesBase, RolesConstants { * @dev Can only be called by the current minter. * @param minter_ The address of the new minter. */ - function proposeMinterRole(address minter_) external onlyRole(uint8(Roles.MINTER)) { + function proposeMintership(address minter_) external onlyRole(uint8(Roles.MINTER)) { _proposeRole(msg.sender, minter_, uint8(Roles.MINTER)); } @@ -46,7 +46,7 @@ contract Minter is IMinter, RolesBase, RolesConstants { * @dev Can only be called by the proposed minter. * @param fromMinter The previous minter. */ - function acceptMinterRole(address fromMinter) external { + function acceptMintership(address fromMinter) external { _acceptRole(fromMinter, msg.sender, uint8(Roles.MINTER)); } diff --git a/contracts/utils/Operatable.sol b/contracts/utils/Operator.sol similarity index 93% rename from contracts/utils/Operatable.sol rename to contracts/utils/Operator.sol index dd24b9e6..168bed67 100644 --- a/contracts/utils/Operatable.sol +++ b/contracts/utils/Operator.sol @@ -4,18 +4,18 @@ pragma solidity ^0.8.0; import { RolesBase } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/RolesBase.sol'; -import { IOperatable } from '../interfaces/IOperatable.sol'; +import { IOperator } from '../interfaces/IOperator.sol'; import { RolesConstants } from './RolesConstants.sol'; /** - * @title Operatable Contract + * @title Operator Contract * @notice A contract module which provides a basic access control mechanism, where * there is an account (a operator) that can be granted exclusive access to * specific functions. * @dev This module is used through inheritance. */ -contract Operatable is IOperatable, RolesBase, RolesConstants { +contract Operator is IOperator, RolesBase, RolesConstants { /** * @notice Internal function that stores the new operator address in the correct storage slot * @param operator The address of the new operator diff --git a/test/InterchainTokenService.js b/test/InterchainTokenService.js index 06b8ac48..a5a81ac4 100644 --- a/test/InterchainTokenService.js +++ b/test/InterchainTokenService.js @@ -142,7 +142,7 @@ describe('Interchain Token Service', () => { await (await token.mint(wallet.address, mintAmount)).wait(); } - await (await token.transferMinterRole(service.address)).wait(); + await (await token.transferMintership(service.address)).wait(); const params = defaultAbiCoder.encode(['bytes', 'address'], [wallet.address, token.address]); await (await service.deployTokenManager(salt, '', type, params, 0)).wait(); diff --git a/test/InterchainTokenServiceFullFlow.js b/test/InterchainTokenServiceFullFlow.js index 62e40e4b..96847dc8 100644 --- a/test/InterchainTokenServiceFullFlow.js +++ b/test/InterchainTokenServiceFullFlow.js @@ -330,7 +330,7 @@ describe('Interchain Token Service Full Flow', () => { await expect(token.mint(newAddress, amount)).to.emit(token, 'Transfer').withArgs(AddressZero, newAddress, amount); await expect(token.burn(newAddress, amount)).to.emit(token, 'Transfer').withArgs(newAddress, AddressZero, amount); - await expect(token.transferMinterRole(newAddress)) + await expect(token.transferMintership(newAddress)) .to.emit(token, 'RolesRemoved') .withArgs(wallet.address, 1 << MINTER_ROLE) .to.emit(token, 'RolesAdded') @@ -420,7 +420,7 @@ describe('Interchain Token Service Full Flow', () => { await expect(token.mint(newAddress, amount)).to.emit(token, 'Transfer').withArgs(AddressZero, newAddress, amount); await expect(token.burn(newAddress, amount)).to.emit(token, 'Transfer').withArgs(newAddress, AddressZero, amount); - await expect(token.transferMinterRole(service.address)) + await expect(token.transferMintership(service.address)) .to.emit(token, 'RolesRemoved') .withArgs(wallet.address, 1 << MINTER_ROLE) .to.emit(token, 'RolesAdded') diff --git a/test/UtilsTest.js b/test/UtilsTest.js index 276fe27d..fe3919ee 100644 --- a/test/UtilsTest.js +++ b/test/UtilsTest.js @@ -20,12 +20,12 @@ before(async () => { otherWallet = wallets[1]; }); -describe('Operatable', () => { +describe('Operator', () => { let test; let operatorRole; before(async () => { - test = await deployContract(ownerWallet, 'TestOperatable', [ownerWallet.address]); + test = await deployContract(ownerWallet, 'TestOperator', [ownerWallet.address]); operatorRole = await test.operatorRole(); }); @@ -119,7 +119,7 @@ describe('Minter', () => { it('Should be able to change the minter only as the minter', async () => { expect(await test.hasRole(ownerWallet.address, minterRole)).to.be.true; - await expect(test.transferMinterRole(otherWallet.address)) + await expect(test.transferMintership(otherWallet.address)) .to.emit(test, 'RolesRemoved') .withArgs(ownerWallet.address, 1 << minterRole) .to.emit(test, 'RolesAdded') @@ -127,7 +127,7 @@ describe('Minter', () => { expect(await test.hasRole(otherWallet.address, minterRole)).to.be.true; - await expectRevert((gasOptions) => test.transferMinterRole(otherWallet.address, gasOptions), test, 'MissingRole', [ + await expectRevert((gasOptions) => test.transferMintership(otherWallet.address, gasOptions), test, 'MissingRole', [ ownerWallet.address, minterRole, ]); @@ -137,13 +137,13 @@ describe('Minter', () => { expect(await test.hasRole(otherWallet.address, minterRole)).to.be.true; await expectRevert( - (gasOptions) => test.connect(ownerWallet).proposeMinterRole(ownerWallet.address, gasOptions), + (gasOptions) => test.connect(ownerWallet).proposeMintership(ownerWallet.address, gasOptions), test, 'MissingRole', [ownerWallet.address, minterRole], ); - await expect(test.connect(otherWallet).proposeMinterRole(ownerWallet.address)) + await expect(test.connect(otherWallet).proposeMintership(ownerWallet.address)) .to.emit(test, 'RolesProposed') .withArgs(otherWallet.address, ownerWallet.address, 1 << minterRole); }); @@ -152,12 +152,12 @@ describe('Minter', () => { expect(await test.hasRole(otherWallet.address, minterRole)).to.be.true; await expectRevert( - (gasOptions) => test.connect(otherWallet).acceptMinterRole(otherWallet.address, gasOptions), + (gasOptions) => test.connect(otherWallet).acceptMintership(otherWallet.address, gasOptions), test, 'InvalidProposedRoles', ); - await expect(test.connect(ownerWallet).acceptMinterRole(otherWallet.address)) + await expect(test.connect(ownerWallet).acceptMintership(otherWallet.address)) .to.emit(test, 'RolesRemoved') .withArgs(otherWallet.address, 1 << minterRole) .to.emit(test, 'RolesAdded')