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

Second audit report fixes #21

Merged
merged 1 commit into from
Apr 17, 2023
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
22 changes: 10 additions & 12 deletions contracts/upgradeable-Bridge/FiberRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity 0.8.2;
import "./FundManager.sol";
import "../common/uniswap/IUniswapV2Router02.sol";
import "../common/uniswap/IWETH.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
Expand Down Expand Up @@ -73,11 +72,11 @@ contract FiberRouter is ReentrancyGuardUpgradeable, OwnableUpgradeable {
@param _token The foundry token address
@param _oracleAddress The oracle address for price feed
*/
function setOracle(address _token, address _oracleAddress)
function setOracle(address _token, AggregatorV3Interface _oracleAddress)
external
onlyOwner
{
priceFeed[_token] = AggregatorV3Interface(_oracleAddress);
priceFeed[_token] = _oracleAddress;
}

function getFoundryTokenPrice(address _token)
Expand All @@ -86,12 +85,11 @@ contract FiberRouter is ReentrancyGuardUpgradeable, OwnableUpgradeable {
returns (uint256)
{
(
,
/*uint80 roundID*/
int256 price, /*uint startedAt*/ /*uint timeStamp*/ /*uint80 answeredInRound*/
,
,

/*uint80 roundID*/,
int256 price,
/*uint startedAt*/,
/*uint timeStamp*/,
/*uint80 answeredInRound*/
) = priceFeed[_token].latestRoundData();
uint8 baseDecimals = priceFeed[_token].decimals();
return uint256(price) * 10**(18 - baseDecimals);
Expand Down Expand Up @@ -127,7 +125,7 @@ contract FiberRouter is ReentrancyGuardUpgradeable, OwnableUpgradeable {
targetToken,
targetAddress
);
Swap(
emit Swap(
token,
targetToken,
block.chainid,
Expand Down Expand Up @@ -217,7 +215,7 @@ contract FiberRouter is ReentrancyGuardUpgradeable, OwnableUpgradeable {
crossTargetNetwork,
crossTargetToken
);
Swap(
emit Swap(
path[0],
crossTargetToken,
block.chainid,
Expand Down Expand Up @@ -313,7 +311,7 @@ contract FiberRouter is ReentrancyGuardUpgradeable, OwnableUpgradeable {
crossTargetNetwork,
crossTargetToken
);
Swap(
emit Swap(
path[0],
crossTargetToken,
block.chainid,
Expand Down
25 changes: 10 additions & 15 deletions contracts/upgradeable-Bridge/FundManager.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.2;

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/cryptography/draft-EIP712Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "../common/signature/SigCheckable.sol";
import "../common/SafeAmount.sol";
import "../common/WithAdmin.sol";
import "../taxing/IGeneralTaxDistributor.sol";

contract FundManager is SigCheckable, WithAdmin, ReentrancyGuardUpgradeable {
contract FundManager is SigCheckable, WithAdmin {
using SafeERC20Upgradeable for IERC20Upgradeable;

address public router;
Expand Down Expand Up @@ -74,7 +71,6 @@ contract FundManager is SigCheckable, WithAdmin, ReentrancyGuardUpgradeable {
function initialize() external initializer {
__EIP712_init(NAME, VERSION);
__Ownable_init();
__ReentrancyGuard_init();
}

/**
Expand Down Expand Up @@ -313,14 +309,13 @@ contract FundManager is SigCheckable, WithAdmin, ReentrancyGuardUpgradeable {
address _signer = signerUnique(message, signature);
require(signers[_signer], "BridgePool: Invalid signer");

uint256 fee = 0;
address _feeDistributor = feeDistributor;
if (_feeDistributor != address(0)) {
uint256 fee;
if (feeDistributor != address(0)) {
fee = (amount * fees[token]) / 10000;
amount -= fee;
if (fee != 0) {
IERC20Upgradeable(token).safeTransfer(_feeDistributor, fee);
IGeneralTaxDistributor(_feeDistributor).distributeTax(token);
IERC20Upgradeable(token).safeTransfer(feeDistributor, fee);
IGeneralTaxDistributor(feeDistributor).distributeTax(token);
}
}
IERC20Upgradeable(token).safeTransfer(payee, amount);
Expand Down Expand Up @@ -430,15 +425,15 @@ contract FundManager is SigCheckable, WithAdmin, ReentrancyGuardUpgradeable {
address targetToken,
address targetAddress
) internal returns (uint256) {
require(
targetAddress != address(0),
"BridgePool: targetAddress is required"
);
require(from != address(0), "BP: bad from");
require(token != address(0), "BP: bad token");
require(amount != 0, "BP: bad amount");
require(targetNetwork != 0, "BP: targetNetwork is requried");
require(targetToken != address(0), "BP: bad target token");
require(amount != 0, "BP: bad amount");
require(
targetAddress != address(0),
"BridgePool: targetAddress is required"
);
require(
allowedTargets[token][targetNetwork] == targetToken,
"BP: target not allowed"
Expand Down