Skip to content

Commit

Permalink
refactor(its): rename valid token methods to more reeadable (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahramy authored Nov 6, 2024
1 parent 588f79c commit 19d27a4
Show file tree
Hide file tree
Showing 6 changed files with 1,161 additions and 1,162 deletions.
2 changes: 1 addition & 1 deletion contracts/InterchainTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ contract InterchainTokenFactory is IInterchainTokenFactory, ITokenManagerType, M
// This ensures that the token manager has been deployed by this address, so it's safe to trust it.
salt = canonicalInterchainTokenSalt(chainNameHash, originalTokenAddress);
tokenId = interchainTokenService.interchainTokenId(TOKEN_FACTORY_DEPLOYER, salt);
token = IInterchainToken(interchainTokenService.validTokenAddress(tokenId));
token = IInterchainToken(interchainTokenService.registeredTokenAddress(tokenId));

// The 3 lines below will revert if the token does not exist.
string memory tokenName = token.name();
Expand Down
41 changes: 20 additions & 21 deletions contracts/InterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -195,24 +195,27 @@ contract InterchainTokenService is
}

/**
* @notice Returns the address of a TokenManager from a specific tokenId.
* @dev The TokenManager needs to exist already.
* @param tokenId The tokenId.
* @return tokenManagerAddress_ The deployment address of the TokenManager.
* @notice Returns the instance of ITokenManager from a specific tokenId.
* @dev This function checks if a token manager contract exists at the address for the specified tokenId.
* If no token manager is deployed for the tokenId, the function will revert with `TokenManagerDoesNotExist`.
* @param tokenId The tokenId of the deployed token manager.
* @return tokenManager_ The instance of ITokenManager associated with the specified tokenId.
*/
function validTokenManagerAddress(bytes32 tokenId) public view returns (address tokenManagerAddress_) {
tokenManagerAddress_ = tokenManagerAddress(tokenId);
function deployedTokenManager(bytes32 tokenId) public view returns (ITokenManager tokenManager_) {
address tokenManagerAddress_ = tokenManagerAddress(tokenId);
if (tokenManagerAddress_.code.length == 0) revert TokenManagerDoesNotExist(tokenId);
tokenManager_ = ITokenManager(tokenManagerAddress_);
}

/**
* @notice Returns the address of the token that an existing tokenManager points to.
* @param tokenId The tokenId.
* @dev This function requires that a token manager is already deployed for the specified tokenId.
* It will call `deployedTokenManager` to get the token manager and return the address of the associated token.
* @param tokenId The tokenId of the registered token.
* @return tokenAddress The address of the token.
*/
function validTokenAddress(bytes32 tokenId) public view returns (address tokenAddress) {
address tokenManagerAddress_ = validTokenManagerAddress(tokenId);
tokenAddress = ITokenManager(tokenManagerAddress_).tokenAddress();
function registeredTokenAddress(bytes32 tokenId) public view returns (address tokenAddress) {
tokenAddress = ITokenManager(deployedTokenManager(tokenId)).tokenAddress();
}

/**
Expand Down Expand Up @@ -251,8 +254,7 @@ contract InterchainTokenService is
* @return flowLimit_ The flow limit.
*/
function flowLimit(bytes32 tokenId) external view returns (uint256 flowLimit_) {
ITokenManager tokenManager_ = ITokenManager(validTokenManagerAddress(tokenId));
flowLimit_ = tokenManager_.flowLimit();
flowLimit_ = deployedTokenManager(tokenId).flowLimit();
}

/**
Expand All @@ -261,8 +263,7 @@ contract InterchainTokenService is
* @return flowOutAmount_ The flow out amount.
*/
function flowOutAmount(bytes32 tokenId) external view returns (uint256 flowOutAmount_) {
ITokenManager tokenManager_ = ITokenManager(validTokenManagerAddress(tokenId));
flowOutAmount_ = tokenManager_.flowOutAmount();
flowOutAmount_ = deployedTokenManager(tokenId).flowOutAmount();
}

/**
Expand All @@ -271,8 +272,7 @@ contract InterchainTokenService is
* @return flowInAmount_ The flow in amount.
*/
function flowInAmount(bytes32 tokenId) external view returns (uint256 flowInAmount_) {
ITokenManager tokenManager_ = ITokenManager(validTokenManagerAddress(tokenId));
flowInAmount_ = tokenManager_.flowInAmount();
flowInAmount_ = deployedTokenManager(tokenId).flowInAmount();
}

/************\
Expand Down Expand Up @@ -572,9 +572,8 @@ contract InterchainTokenService is
if (length != flowLimits.length) revert LengthMismatch();

for (uint256 i; i < length; ++i) {
ITokenManager tokenManager_ = ITokenManager(validTokenManagerAddress(tokenIds[i]));
// slither-disable-next-line calls-loop
tokenManager_.setFlowLimit(flowLimits[i]);
deployedTokenManager(tokenIds[i]).setFlowLimit(flowLimits[i]);
}
}

Expand Down Expand Up @@ -880,7 +879,7 @@ contract InterchainTokenService is
bytes calldata params
) internal {
// slither-disable-next-line unused-return
validTokenManagerAddress(tokenId);
deployedTokenManager(tokenId);

emit TokenManagerDeploymentStarted(tokenId, destinationChain, tokenManagerType, params);

Expand Down Expand Up @@ -909,7 +908,7 @@ contract InterchainTokenService is
uint256 gasValue
) internal {
// slither-disable-next-line unused-return
validTokenManagerAddress(tokenId);
deployedTokenManager(tokenId);

// slither-disable-next-line reentrancy-events
emit InterchainTokenDeploymentStarted(tokenId, name, symbol, decimals, minter, destinationChain);
Expand Down Expand Up @@ -1093,7 +1092,7 @@ contract InterchainTokenService is
revert InvalidExpressMessageType(messageType);
}

return (validTokenAddress(tokenId), amount);
return (registeredTokenAddress(tokenId), amount);
}

function _getExpressExecutorAndEmitEvent(
Expand Down
13 changes: 7 additions & 6 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IPausable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/int
import { IUpgradable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IUpgradable.sol';

import { ITransmitInterchainToken } from './ITransmitInterchainToken.sol';
import { ITokenManager } from './ITokenManager.sol';
import { ITokenManagerType } from './ITokenManagerType.sol';
import { ITokenManagerImplementation } from './ITokenManagerImplementation.sol';
import { IOperator } from './IOperator.sol';
Expand Down Expand Up @@ -136,18 +137,18 @@ interface IInterchainTokenService is
function tokenManagerAddress(bytes32 tokenId) external view returns (address tokenManagerAddress_);

/**
* @notice Returns the address of the valid token manager associated with the given tokenId.
* @param tokenId The tokenId of the token manager.
* @return tokenManagerAddress_ The address of the valid token manager.
* @notice Returns the instance of ITokenManager from a specific tokenId.
* @param tokenId The tokenId of the deployed token manager.
* @return tokenManager_ The instance of ITokenManager associated with the specified tokenId.
*/
function validTokenManagerAddress(bytes32 tokenId) external view returns (address tokenManagerAddress_);
function deployedTokenManager(bytes32 tokenId) external view returns (ITokenManager tokenManager_);

/**
* @notice Returns the address of the token that an existing tokenManager points to.
* @param tokenId The tokenId of the token manager.
* @param tokenId The tokenId of the registered token.
* @return tokenAddress The address of the token.
*/
function validTokenAddress(bytes32 tokenId) external view returns (address tokenAddress);
function registeredTokenAddress(bytes32 tokenId) external view returns (address tokenAddress);

/**
* @notice Returns the address of the interchain token associated with the given tokenId.
Expand Down
Loading

0 comments on commit 19d27a4

Please sign in to comment.