Skip to content

Commit

Permalink
merge main again
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Apr 15, 2024
1 parent aea48a7 commit b4b04d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 4 additions & 5 deletions contracts/TokenHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ITokenManagerType } from './interfaces/ITokenManagerType.sol';
import { ITokenManager } from './interfaces/ITokenManager.sol';
import { ITokenManagerProxy } from './interfaces/ITokenManagerProxy.sol';
import { IERC20MintableBurnable } from './interfaces/IERC20MintableBurnable.sol';
import { IERC20BurnableFrom } from './interfaces/IERC20BurnableFrom.sol';
import { IERC20Named } from './interfaces/IERC20Named.sol';

/**
Expand Down Expand Up @@ -105,9 +104,9 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea
if (tokenManagerType == uint256(TokenManagerType.NATIVE_INTERCHAIN_TOKEN)) {
_takeInterchainToken(tokenAddress, from, amount);
} else if (tokenManagerType == uint256(TokenManagerType.MINT_BURN)) {
_takeTokenMintBurn(tokenAddress, from, amount);
_burnToken(tokenManager, tokenAddress, from, amount);
} else if (tokenManagerType == uint256(TokenManagerType.MINT_BURN_FROM)) {
_takeTokenMintBurnFrom(tokenAddress, from, amount);
_burnTokenFrom(tokenManager, tokenAddress, from, amount);
} else if (tokenManagerType == uint256(TokenManagerType.LOCK_UNLOCK)) {
_transferTokenFrom(tokenAddress, from, tokenManager, amount);
} else if (tokenManagerType == uint256(TokenManagerType.LOCK_UNLOCK_FEE)) {
Expand Down Expand Up @@ -220,8 +219,8 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea
ITokenManager(tokenManager).burnToken(tokenAddress, from, amount);
}

function _burnTokenFrom(address tokenAddress, address from, uint256 amount) internal {
IERC20(tokenAddress).safeCall(abi.encodeWithSelector(IERC20BurnableFrom.burnFrom.selector, from, amount));
function _burnTokenFrom(address tokenManager, address tokenAddress, address from, uint256 amount) internal {
ITokenManager(tokenManager).burnTokenFrom(tokenAddress, from, amount);
}

function _approveGateway(address tokenAddress, uint256 amount) internal {
Expand Down
9 changes: 9 additions & 0 deletions contracts/interfaces/ITokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ interface ITokenManager is IBaseTokenManager, IOperator, IFlowLimit, IImplementa
* @param amount The amount to burn.
*/
function burnToken(address tokenAddress_, address from, uint256 amount) external;

/**
* @notice External function to allow the service to burn tokens through the tokenManager
* @dev This function should revert if called by anyone but the service.
* @param tokenAddress_ The address of the token, since its cheaper to pass it in instead of reading it as the token manager.
* @param from The address to burn the token from.
* @param amount The amount to burn.
*/
function burnTokenFrom(address tokenAddress_, address from, uint256 amount) external;
}
12 changes: 12 additions & 0 deletions contracts/token-manager/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Multicall } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/uti

import { ITokenManager } from '../interfaces/ITokenManager.sol';
import { IERC20MintableBurnable } from '../interfaces/IERC20MintableBurnable.sol';
import { IERC20BurnableFrom } from '../interfaces/IERC20BurnableFrom.sol';

import { Operator } from '../utils/Operator.sol';
import { FlowLimit } from '../utils/FlowLimit.sol';
Expand Down Expand Up @@ -213,4 +214,15 @@ contract TokenManager is ITokenManager, Operator, FlowLimit, Implementation, Mul
function burnToken(address tokenAddress_, address from, uint256 amount) external onlyService {
IERC20(tokenAddress_).safeCall(abi.encodeWithSelector(IERC20MintableBurnable.burn.selector, from, amount));
}

/**
* @notice External function to allow the service to burn tokens through the tokenManager
* @dev This function should revert if called by anyone but the service.
* @param tokenAddress_ The address of the token, since its cheaper to pass it in instead of reading it as the token manager.
* @param from The address to burn the token from.
* @param amount The amount to burn.
*/
function burnTokenFrom(address tokenAddress_, address from, uint256 amount) external onlyService {
IERC20(tokenAddress_).safeCall(abi.encodeWithSelector(IERC20BurnableFrom.burnFrom.selector, from, amount));
}
}

0 comments on commit b4b04d6

Please sign in to comment.