Skip to content

Commit

Permalink
Merge branch 'feat/token-manager-mint-interchain-tokens-2' into feat/…
Browse files Browse the repository at this point in the history
…manual-migrate-tokens
  • Loading branch information
Foivos committed Jan 10, 2025
2 parents 716fb46 + 5bcb97a commit e4f3152
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
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.
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.
// This is done here because InterchainToken bytecode needs to be fixed.
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;
}

0 comments on commit e4f3152

Please sign in to comment.