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: added automatic token migration #317

Open
wants to merge 7 commits into
base: feat/manual-migrate-tokens
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions contracts/TokenHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea
/// @dev Track the flow amount being received via the message
ITokenManager(tokenManager).addFlowIn(amount);
Comment on lines 38 to 39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// @dev Track the flow amount being received via the message
ITokenManager(tokenManager).addFlowIn(amount);
_migrateToken(tokenManager, tokenAddress, tokenManagerType);
/// @dev Track the flow amount being received via the message
ITokenManager(tokenManager).addFlowIn(amount);

call migrate separately so it's cleaner, gas cost difference should be very small

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean call it for every token type? indiscriminately? This would revert if the token in question does not implement isMinter


if (tokenManagerType == uint256(TokenManagerType.NATIVE_INTERCHAIN_TOKEN)) {
_migrateToken(tokenManager, tokenAddress);
_mintToken(tokenManager, tokenAddress, to, amount);
return (amount, tokenAddress);
}

if (
tokenManagerType == uint256(TokenManagerType.NATIVE_INTERCHAIN_TOKEN) ||
tokenManagerType == uint256(TokenManagerType.MINT_BURN) ||
tokenManagerType == uint256(TokenManagerType.MINT_BURN_FROM)
) {
Expand Down Expand Up @@ -75,9 +80,10 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea

if (tokenOnly && msg.sender != tokenAddress) revert NotToken(msg.sender, tokenAddress);

if (
tokenManagerType == uint256(TokenManagerType.NATIVE_INTERCHAIN_TOKEN) || tokenManagerType == uint256(TokenManagerType.MINT_BURN)
) {
if (tokenManagerType == uint256(TokenManagerType.NATIVE_INTERCHAIN_TOKEN)) {
_migrateToken(tokenManager, tokenAddress);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

_burnToken(tokenManager, tokenAddress, from, amount);
} else if (tokenManagerType == uint256(TokenManagerType.MINT_BURN)) {
_burnToken(tokenManager, tokenAddress, from, amount);
} else if (tokenManagerType == uint256(TokenManagerType.MINT_BURN_FROM)) {
_burnTokenFrom(tokenAddress, from, amount);
Expand Down Expand Up @@ -172,4 +178,10 @@ contract TokenHandler is ITokenHandler, ITokenManagerType, ReentrancyGuard, Crea
function _burnTokenFrom(address tokenAddress, address from, uint256 amount) internal {
IERC20(tokenAddress).safeCall(abi.encodeWithSelector(IERC20BurnableFrom.burnFrom.selector, from, amount));
}

function _migrateToken(address tokenManager, address tokenAddress) internal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a docstring to explain this auto migration feature

if (IMinter(tokenAddress).isMinter(address(this))) {
IMinter(tokenAddress).transferMintership(tokenManager);
}
}
}
Loading