Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(token-handler)!: give interchain token mint/burn permission to token manager #314

Merged
merged 11 commits into from
Jan 15, 2025
5 changes: 5 additions & 0 deletions .changeset/many-tigers-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/interchain-token-service': minor
---

Interchain tokens now get minted/burnt by the token manager.
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 16 additions & 12 deletions contracts/TokenHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea
tokenManagerType == uint256(TokenManagerType.MINT_BURN) ||
tokenManagerType == uint256(TokenManagerType.MINT_BURN_FROM)
) {
_mintToken(tokenManager, tokenAddress, to, amount);
_mintToken(ITokenManager(tokenManager), tokenAddress, to, amount);
return (amount, tokenAddress);
}

Expand Down Expand Up @@ -78,7 +78,7 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea
if (
tokenManagerType == uint256(TokenManagerType.NATIVE_INTERCHAIN_TOKEN) || tokenManagerType == uint256(TokenManagerType.MINT_BURN)
) {
_burnToken(tokenManager, tokenAddress, from, amount);
_burnToken(ITokenManager(tokenManager), tokenAddress, from, amount);
} else if (tokenManagerType == uint256(TokenManagerType.MINT_BURN_FROM)) {
_burnTokenFrom(tokenAddress, from, amount);
} else if (tokenManagerType == uint256(TokenManagerType.LOCK_UNLOCK)) {
Expand Down Expand Up @@ -132,12 +132,16 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea
* @param tokenManager The address of the token manager.
*/
// slither-disable-next-line locked-ether
function postTokenManagerDeploy(uint256 tokenManagerType, address tokenManager) external payable {
// For lock/unlock token managers, the ITS contract needs an approval from the token manager to transfer tokens on its behalf
if (tokenManagerType == uint256(TokenManagerType.LOCK_UNLOCK) || tokenManagerType == uint256(TokenManagerType.LOCK_UNLOCK_FEE)) {
ITokenManager(tokenManager).approveService();
} else if (tokenManagerType == uint256(TokenManagerType.NATIVE_INTERCHAIN_TOKEN)) {
IMinter(ITokenManager(tokenManager).tokenAddress()).transferMintership(tokenManager);
function postTokenManagerDeploy(uint256 tokenManagerType, ITokenManager tokenManager) external payable {
// For native interhcain tokens we transfer mintership to the token manager.
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
// This is done here because InterchainToken bytecode needs to be fixed.
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
if (tokenManagerType == uint256(TokenManagerType.NATIVE_INTERCHAIN_TOKEN)) {
IMinter(tokenManager.tokenAddress()).transferMintership(address(tokenManager));
// For lock/unlock token managers, the ITS contract needs an approval from the token manager to transfer tokens on its behalf.
} else if (
tokenManagerType == uint256(TokenManagerType.LOCK_UNLOCK) || tokenManagerType == uint256(TokenManagerType.LOCK_UNLOCK_FEE)
) {
tokenManager.approveService();
}
}

Expand All @@ -161,12 +165,12 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea
return diff < amount ? diff : amount;
}

function _mintToken(address tokenManager, address tokenAddress, address to, uint256 amount) internal {
ITokenManager(tokenManager).mintToken(tokenAddress, to, amount);
function _mintToken(ITokenManager tokenManager, address tokenAddress, address to, uint256 amount) internal {
tokenManager.mintToken(tokenAddress, to, amount);
}

function _burnToken(address tokenManager, address tokenAddress, address from, uint256 amount) internal {
ITokenManager(tokenManager).burnToken(tokenAddress, from, amount);
function _burnToken(ITokenManager tokenManager, address tokenAddress, address from, uint256 amount) internal {
tokenManager.burnToken(tokenAddress, from, amount);
}

function _burnTokenFrom(address tokenAddress, address from, uint256 amount) internal {
Expand Down
4 changes: 3 additions & 1 deletion contracts/interfaces/ITokenHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pragma solidity ^0.8.0;

import { ITokenManager } from './ITokenManager.sol';

/**
* @title ITokenHandler Interface
* @notice This interface is responsible for handling tokens before initiating an interchain token transfer, or after receiving one.
Expand Down Expand Up @@ -47,5 +49,5 @@ interface ITokenHandler {
* @param tokenManagerType The token manager type.
* @param tokenManager The address of the token manager.
*/
function postTokenManagerDeploy(uint256 tokenManagerType, address tokenManager) external payable;
function postTokenManagerDeploy(uint256 tokenManagerType, ITokenManager tokenManager) external payable;
}