Skip to content

Commit

Permalink
refactor: change tokenId getter to interchainTokenId (#142)
Browse files Browse the repository at this point in the history
* refactor: tokenId() -> interchainTokenId()

* tokenId_ -> tokenId

* revert incorrect rename ocurrences

* lint
  • Loading branch information
milapsheth authored Nov 3, 2023
1 parent 3ac2eed commit 928a1bf
Show file tree
Hide file tree
Showing 10 changed files with 2,949 additions and 2,705 deletions.
207 changes: 99 additions & 108 deletions contracts/interchain-token-service/InterchainTokenService.sol

Large diffs are not rendered by default.

72 changes: 36 additions & 36 deletions contracts/interfaces/IInterchainTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
error LengthMismatch();
error InvalidTokenManagerImplementationType(address implementation);
error NotRemoteService();
error TokenManagerDoesNotExist(bytes32 tokenId_);
error TokenManagerDoesNotExist(bytes32 tokenId);
error NotTokenManager(address caller, address tokenManager);
error ExecuteWithInterchainTokenFailed(address contractAddress);
error InvalidCanonicalTokenId(bytes32 expectedCanonicalTokenId);
Expand All @@ -29,38 +29,38 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
error UntrustedChain(string chainName);
error InvalidExpressSelector(uint256 selector);

event TokenSent(bytes32 indexed tokenId_, string destinationChain, bytes destinationAddress, uint256 indexed amount);
event TokenSent(bytes32 indexed tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);
event TokenSentWithData(
bytes32 indexed tokenId_,
bytes32 indexed tokenId,
string destinationChain,
bytes destinationAddress,
uint256 indexed amount,
address indexed sourceAddress,
bytes data
);
event TokenReceived(
bytes32 indexed tokenId_,
bytes32 indexed tokenId,
string sourceChain,
bytes sourceAddress,
address indexed destinationAddress,
uint256 indexed amount
);
event TokenReceivedWithData(
bytes32 indexed tokenId_,
bytes32 indexed tokenId,
string sourceChain,
bytes sourceAddress,
address indexed destinationAddress,
uint256 indexed amount
);
event RemoteTokenManagerDeploymentInitialized(
bytes32 indexed tokenId_,
bytes32 indexed tokenId,
string destinationChain,
uint256 indexed gasValue,
TokenManagerType indexed tokenManagerType,
bytes params
);
event RemoteInterchainTokenDeploymentInitialized(
bytes32 indexed tokenId_,
bytes32 indexed tokenId,
string tokenName,
string tokenSymbol,
uint8 tokenDecimals,
Expand All @@ -69,16 +69,16 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
string destinationChain,
uint256 indexed gasValue
);
event TokenManagerDeployed(bytes32 indexed tokenId_, address tokenManager, TokenManagerType indexed tokenManagerType, bytes params);
event TokenManagerDeployed(bytes32 indexed tokenId, address tokenManager, TokenManagerType indexed tokenManagerType, bytes params);
event InterchainTokenDeployed(
bytes32 indexed tokenId_,
bytes32 indexed tokenId,
address tokenAddress,
address indexed distributor,
string name,
string symbol,
uint8 decimals
);
event CustomTokenIdClaimed(bytes32 indexed tokenId_, address indexed deployer, bytes32 indexed salt);
event CustomTokenIdClaimed(bytes32 indexed tokenId, address indexed deployer, bytes32 indexed salt);
event PausedSet(bool indexed paused, address indexed msgSender);

/**
Expand All @@ -100,40 +100,40 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
function interchainTokenDeployer() external view returns (address interchainTokenDeployerAddress);

/**
* @notice Returns the address of the token manager associated with the given tokenId_.
* @param tokenId_ The tokenId_ of the token manager.
* @notice Returns the address of the token manager associated with the given tokenId.
* @param tokenId The tokenId of the token manager.
* @return tokenManagerAddress_ The address of the token manager.
*/
function tokenManagerAddress(bytes32 tokenId_) external view returns (address tokenManagerAddress_);
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.
* @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.
*/
function validTokenManagerAddress(bytes32 tokenId_) external view returns (address tokenManagerAddress_);
function validTokenManagerAddress(bytes32 tokenId) external view returns (address tokenManagerAddress_);

/**
* @notice Returns the address of the token associated with the given tokenId_.
* @param tokenId_ The tokenId_ of the token manager.
* @notice Returns the address of the token associated with the given tokenId.
* @param tokenId The tokenId of the token manager.
* @return tokenAddress_ The address of the token.
*/
function tokenAddress(bytes32 tokenId_) external view returns (address tokenAddress_);
function tokenAddress(bytes32 tokenId) external view returns (address tokenAddress_);

/**
* @notice Returns the address of the standardized token associated with the given tokenId_.
* @param tokenId_ The tokenId_ of the standardized token.
* @notice Returns the address of the standardized token associated with the given tokenId.
* @param tokenId The tokenId of the standardized token.
* @return tokenAddress_ The address of the standardized token.
*/
function interchainTokenAddress(bytes32 tokenId_) external view returns (address tokenAddress_);
function interchainTokenAddress(bytes32 tokenId) external view returns (address tokenAddress_);

/**
* @notice Returns the custom tokenId_ associated with the given operator and salt.
* @notice Returns the custom tokenId associated with the given operator and salt.
* @param operator_ The operator address.
* @param salt The salt used for token id calculation.
* @return tokenId_ The custom tokenId_ associated with the operator and salt.
* @return tokenId The custom tokenId associated with the operator and salt.
*/
function tokenId(address operator_, bytes32 salt) external view returns (bytes32 tokenId_);
function interchainTokenId(address operator_, bytes32 salt) external view returns (bytes32 tokenId);

/**
* @notice Deploys a custom token manager contract on a remote chain.
Expand All @@ -149,7 +149,7 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
TokenManagerType tokenManagerType,
bytes calldata params,
uint256 gasValue
) external payable returns (bytes32 tokenId_);
) external payable returns (bytes32 tokenId);

/**
* @notice Deploys and registers a standardized token on a remote chain.
Expand Down Expand Up @@ -180,15 +180,15 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec
function tokenManagerImplementation(uint256 tokenManagerType) external view returns (address tokenManagerAddress_);

function interchainTransfer(
bytes32 tokenId_,
bytes32 tokenId,
string calldata destinationChain,
bytes calldata destinationAddress,
uint256 amount,
bytes calldata metadata
) external payable;

function sendTokenWithData(
bytes32 tokenId_,
bytes32 tokenId,
string calldata destinationChain,
bytes calldata destinationAddress,
uint256 amount,
Expand All @@ -197,15 +197,15 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec

/**
* @notice Initiates an interchain token transfer. Only callable by TokenManagers
* @param tokenId_ The tokenId_ of the token to be transmitted.
* @param tokenId The tokenId of the token to be transmitted.
* @param sourceAddress The source address of the token.
* @param destinationChain The name of the destination chain.
* @param destinationAddress The destination address on the destination chain.
* @param amount The amount of tokens to transmit.
* @param metadata The metadata associated with the transmission.
*/
function transmitSendToken(
bytes32 tokenId_,
bytes32 tokenId,
address sourceAddress,
string calldata destinationChain,
bytes memory destinationAddress,
Expand All @@ -222,24 +222,24 @@ interface IInterchainTokenService is ITokenManagerType, IAxelarValuedExpressExec

/**
* @notice Returns the flow limit for a specific token.
* @param tokenId_ The tokenId_ of the token.
* @param tokenId The tokenId of the token.
* @return flowLimit_ The flow limit for the token.
*/
function flowLimit(bytes32 tokenId_) external view returns (uint256 flowLimit_);
function flowLimit(bytes32 tokenId) external view returns (uint256 flowLimit_);

/**
* @notice Returns the total amount of outgoing flow for a specific token.
* @param tokenId_ The tokenId_ of the token.
* @param tokenId The tokenId of the token.
* @return flowOutAmount_ The total amount of outgoing flow for the token.
*/
function flowOutAmount(bytes32 tokenId_) external view returns (uint256 flowOutAmount_);
function flowOutAmount(bytes32 tokenId) external view returns (uint256 flowOutAmount_);

/**
* @notice Returns the total amount of incoming flow for a specific token.
* @param tokenId_ The tokenId_ of the token.
* @param tokenId The tokenId of the token.
* @return flowInAmount_ The total amount of incoming flow for the token.
*/
function flowInAmount(bytes32 tokenId_) external view returns (uint256 flowInAmount_);
function flowInAmount(bytes32 tokenId) external view returns (uint256 flowInAmount_);

/**
* @notice Sets the paused state of the contract.
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ITokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface ITokenManager is ITokenManagerType, IOperatable, IFlowLimit, IImplemen
/**
* @notice A function that returns the token id.
*/
function tokenId() external view returns (bytes32);
function interchainTokenId() external view returns (bytes32);

/**
* @notice A function that should return the address of the token.
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/ITokenManagerProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ interface ITokenManagerProxy {
/**
* @notice Returns token ID of the token manager.
*/
function tokenId() external view returns (bytes32);
function interchainTokenId() external view returns (bytes32);
}
8 changes: 4 additions & 4 deletions contracts/proxies/TokenManagerProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import { ITokenManagerProxy } from '../interfaces/ITokenManagerProxy.sol';
contract TokenManagerProxy is ITokenManagerProxy {
IInterchainTokenService public immutable interchainTokenService;
uint256 public immutable implementationType;
bytes32 public immutable tokenId;
bytes32 public immutable interchainTokenId;

/**
* @dev Constructs the TokenManagerProxy contract.
* @param interchainTokenServiceAddress_ The address of the interchain token service
* @param implementationType_ The token manager type
* @param tokenId_ The identifier for the token
* @param tokenId The identifier for the token
* @param params The initialization parameters for the token manager contract
*/
constructor(address interchainTokenServiceAddress_, uint256 implementationType_, bytes32 tokenId_, bytes memory params) {
constructor(address interchainTokenServiceAddress_, uint256 implementationType_, bytes32 tokenId, bytes memory params) {
interchainTokenService = IInterchainTokenService(interchainTokenServiceAddress_);
implementationType = implementationType_;
tokenId = tokenId_;
interchainTokenId = tokenId;
address impl = _tokenManagerImplementation(IInterchainTokenService(interchainTokenServiceAddress_), implementationType_);

(bool success, bytes memory returnData) = impl.delegatecall(abi.encodeWithSelector(TokenManagerProxy.setup.selector, params));
Expand Down
12 changes: 6 additions & 6 deletions contracts/token-manager/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
* @notice A function that returns the token id.
* @dev This will only work when implementation is called by a proxy, which stores the tokenId as an immutable.
*/
function tokenId() public view returns (bytes32) {
function interchainTokenId() public view returns (bytes32) {
// slither-disable-next-line var-read-using-this
return this.tokenId();
return this.interchainTokenId();
}

/**
Expand Down Expand Up @@ -109,7 +109,7 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
_addFlowOut(amount);

interchainTokenService.transmitSendToken{ value: msg.value }(
tokenId(),
interchainTokenId(),
sender,
destinationChain,
destinationAddress,
Expand All @@ -136,7 +136,7 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
_addFlowOut(amount);
uint32 version = 0;
interchainTokenService.transmitSendToken{ value: msg.value }(
tokenId(),
interchainTokenId(),
sender,
destinationChain,
destinationAddress,
Expand All @@ -163,7 +163,7 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
amount = _takeToken(sender, amount);
_addFlowOut(amount);
interchainTokenService.transmitSendToken{ value: msg.value }(
tokenId(),
interchainTokenId(),
sender,
destinationChain,
destinationAddress,
Expand Down Expand Up @@ -225,7 +225,7 @@ abstract contract TokenManager is ITokenManager, Operatable, FlowLimit, Implemen
* @param flowLimit_ the maximum difference between the tokens flowing in and/or out at any given interval of time (6h)
*/
function setFlowLimit(uint256 flowLimit_) external onlyRole(uint8(Roles.FLOW_LIMITER)) {
_setFlowLimit(flowLimit_, tokenId());
_setFlowLimit(flowLimit_, interchainTokenId());
}

/**
Expand Down
10 changes: 5 additions & 5 deletions contracts/token-registrars/TokenRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract TokenRegistrar is ITokenRegistrar, ITokenManagerType, Multicall, Upgrad
}

function standardizedTokenId(address deployer, bytes32 salt) public view returns (bytes32 tokenId) {
tokenId = service.tokenId(address(this), standardizedTokenSalt(chainNameHash, deployer, salt));
tokenId = service.interchainTokenId(address(this), standardizedTokenSalt(chainNameHash, deployer, salt));
}

function interchainTokenAddress(address deployer, bytes32 salt) public view returns (address tokenAddress) {
Expand Down Expand Up @@ -77,7 +77,7 @@ contract TokenRegistrar is ITokenRegistrar, ITokenManagerType, Multicall, Upgrad
_deployInterchainToken(salt, '', name, symbol, decimals, distributorBytes, operator.toBytes(), 0);

if (mintAmount > 0) {
bytes32 tokenId = service.tokenId(address(this), salt);
bytes32 tokenId = service.interchainTokenId(address(this), salt);
IStandardizedToken token = IStandardizedToken(service.interchainTokenAddress(tokenId));
token.mint(address(this), mintAmount);
token.transferDistributorship(distributor);
Expand Down Expand Up @@ -107,7 +107,7 @@ contract TokenRegistrar is ITokenRegistrar, ITokenManagerType, Multicall, Upgrad
}
address sender = msg.sender;
salt = standardizedTokenSalt(chainNameHash_, sender, salt);
bytes32 tokenId = service.tokenId(address(this), salt);
bytes32 tokenId = service.interchainTokenId(address(this), salt);

IStandardizedToken token = IStandardizedToken(service.interchainTokenAddress(tokenId));
ITokenManager tokenManager = ITokenManager(service.tokenManagerAddress(tokenId));
Expand Down Expand Up @@ -157,7 +157,7 @@ contract TokenRegistrar is ITokenRegistrar, ITokenManagerType, Multicall, Upgrad
}

function canonicalTokenId(address tokenAddress) public view returns (bytes32 tokenId) {
tokenId = service.tokenId(address(this), canonicalTokenSalt(chainNameHash, tokenAddress));
tokenId = service.interchainTokenId(address(this), canonicalTokenSalt(chainNameHash, tokenAddress));
}

function registerCanonicalToken(address tokenAddress) external payable returns (bytes32 tokenId) {
Expand All @@ -184,7 +184,7 @@ contract TokenRegistrar is ITokenRegistrar, ITokenManagerType, Multicall, Upgrad
}
// This ensures that the token manager has been deployed by this address, so it's safe to trust it.
salt = canonicalTokenSalt(chainNameHash_, originalTokenAddress);
bytes32 tokenId = service.tokenId(address(this), salt);
bytes32 tokenId = service.interchainTokenId(address(this), salt);
token = IStandardizedToken(service.tokenAddress(tokenId));
}

Expand Down
Loading

0 comments on commit 928a1bf

Please sign in to comment.