Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/Facets/AxelarFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.13;
import { IAxelarGasService } from "@axelar-network/axelar-cgp-solidity/contracts/interfaces/IAxelarGasService.sol";
import { IAxelarGateway } from "@axelar-network/axelar-cgp-solidity/contracts/interfaces/IAxelarGateway.sol";
import { LibDiamond } from "../Libraries/LibDiamond.sol";
import { LibAsset } from "../Libraries/LibAsset.sol";
import { IERC20 } from "@axelar-network/axelar-cgp-solidity/contracts/interfaces/IERC20.sol";

contract AxelarFacet {
Expand Down Expand Up @@ -67,7 +68,7 @@ contract AxelarFacet {
Storage storage s = getStorage();

address tokenAddress = s.gateway.tokenAddresses(symbol);
IERC20(tokenAddress).transferFrom(msg.sender, address(this), amount);
LibAsset.transferFromERC20(tokenAddress, msg.sender, address(this), amount);
IERC20(tokenAddress).approve(address(s.gateway), amount);

bytes memory payload = abi.encodePacked(callTo, callData);
Expand Down
11 changes: 7 additions & 4 deletions src/Libraries/LibAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ library LibAsset {
) internal {
if (assetId == NATIVE_ASSETID) revert NullAddrIsNotAnERC20Token();
if (to == NULL_ADDRESS) revert NoTransferToNullAddress();
SafeERC20.safeTransferFrom(IERC20(assetId), from, to, amount);

IERC20 asset = IERC20(assetId);
uint256 prevBalance = asset.balanceOf(to);
SafeERC20.safeTransferFrom(asset, from, to, amount);
if (asset.balanceOf(to) - prevBalance != amount) revert InvalidAmount();
}

/// @notice Deposits an asset into the contract and performs checks to avoid NativeValueWithERC
Expand All @@ -96,9 +100,8 @@ library LibAsset {
if (isNative) {
if (msg.value < amount) revert InvalidAmount();
} else {
uint256 _fromTokenBalance = LibAsset.getOwnBalance(tokenId);
LibAsset.transferFromERC20(tokenId, msg.sender, address(this), amount);
if (LibAsset.getOwnBalance(tokenId) - _fromTokenBalance != amount) revert InvalidAmount();
if (msg.value != 0) revert NativeValueWithERC();
transferFromERC20(tokenId, msg.sender, address(this), amount);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Periphery/ERC20Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { LibAsset } from "../Libraries/LibAsset.sol";

/// @title ERC20 Proxy
/// @author LI.FI (https://li.fi)
Expand Down Expand Up @@ -43,6 +43,6 @@ contract ERC20Proxy is Ownable {
) external {
if (!authorizedCallers[msg.sender]) revert UnAuthorized();

IERC20(tokenAddress).transferFrom(from, to, amount);
LibAsset.transferFromERC20(tokenAddress, from, to, amount);
}
}
3 changes: 2 additions & 1 deletion src/Periphery/FusePoolZap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity 0.8.13;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { LibAsset } from "../Libraries/LibAsset.sol";

interface IFusePool {
function cTokensByUnderlying(address) external view returns (address);
Expand Down Expand Up @@ -71,7 +72,7 @@ contract FusePoolZap {

uint256 preMintBalance = IERC20(address(fToken)).balanceOf(address(this));

IERC20(_supplyToken).transferFrom(msg.sender, address(this), _amount);
LibAsset.transferFromERC20(_supplyToken, msg.sender, address(this), _amount);
IERC20(_supplyToken).approve(address(fToken), _amount);
fToken.mint(_amount);

Expand Down