Skip to content

Commit

Permalink
Detect unsupported token
Browse files Browse the repository at this point in the history
  • Loading branch information
wcgcyx committed Dec 11, 2023
1 parent 1e81ee7 commit d0bdd2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/interfaces/root/IRootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,6 @@ interface IRootERC20BridgeErrors {
error ImxDepositLimitTooLow();
/// @notice Error when native transfer is sent to contract from non wrapped-token address.
error NonWrappedNativeTransfer();
/// @notice Error when attempt to map a ERC20 token that doesn't support name(), symbol() or decimals().
error NotSupportedToken();
}
25 changes: 23 additions & 2 deletions src/root/RootERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,29 @@ contract RootERC20Bridge is

rootTokenToChildToken[address(rootToken)] = childToken;

bytes memory payload =
abi.encode(MAP_TOKEN_SIG, rootToken, rootToken.name(), rootToken.symbol(), rootToken.decimals());
string memory tokenName;
string memory tokenSymbol;
uint8 tokenDecimals;

try rootToken.name() returns (string memory name) {
tokenName = name;
} catch {
revert NotSupportedToken();
}

try rootToken.symbol() returns (string memory symbol) {
tokenSymbol = symbol;
} catch {
revert NotSupportedToken();
}

try rootToken.decimals() returns (uint8 decimals) {
tokenDecimals = decimals;
} catch {
revert NotSupportedToken();
}

bytes memory payload = abi.encode(MAP_TOKEN_SIG, rootToken, tokenName, tokenSymbol, tokenDecimals);
rootBridgeAdaptor.sendMessage{value: msg.value}(payload, msg.sender);

emit L1TokenMapped(address(rootToken), childToken);
Expand Down

0 comments on commit d0bdd2d

Please sign in to comment.