From 1195927c2de28ffffadf862c7052bf1ba1833cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Claudio=20Nale?= Date: Sat, 5 Oct 2024 10:41:05 -0300 Subject: [PATCH] evm: fixes canonical chain token redeem --- evm/src/assets/TbrUser.sol | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/evm/src/assets/TbrUser.sol b/evm/src/assets/TbrUser.sol index 137d5f0d..2455c8f1 100644 --- a/evm/src/assets/TbrUser.sol +++ b/evm/src/assets/TbrUser.sol @@ -475,18 +475,23 @@ abstract contract TbrUser is TbrBase { // Perform redeem in TB tokenBridge.completeTransferWithPayload(vaa); - IERC20Metadata token = IERC20Metadata(tokenBridge.wrappedAsset(tokenOriginChain, tokenOriginAddress)); + address token; + if (whChainId != tokenOriginChain) { + token = tokenBridge.wrappedAsset(tokenOriginChain, tokenOriginAddress); + } else { + token = fromUniversalAddress(tokenOriginAddress); + } // If an unwrap is desired, unwrap and call recipient with full amount uint totalGasTokenAmount = gasDropoff; - if (address(gasToken) == address(token) && unwrapIntent && gasErc20TokenizationIsExplicit) { + if (address(gasToken) == token && unwrapIntent && gasErc20TokenizationIsExplicit) { gasToken.withdraw(tokenAmount); totalGasTokenAmount += tokenAmount; } else { // Otherwise, transfer tokens and perform gas dropoff - SafeERC20.safeTransfer(token, recipient, tokenAmount); + SafeERC20.safeTransfer(IERC20Metadata(token), recipient, tokenAmount); } if (totalGasTokenAmount > 0) { // FIXME: we need to put an upper bound on the read bytes to ensure that the contract doesn't run out of gas.