diff --git a/contracts/common/FeeConfiguration.sol b/contracts/common/FeeConfiguration.sol index dd3de9e..dcf1f40 100644 --- a/contracts/common/FeeConfiguration.sol +++ b/contracts/common/FeeConfiguration.sol @@ -74,13 +74,8 @@ abstract contract FeeConfiguration is AccessControl { address _token = feeConfig.token; uint256 fee = _calculateFee(_amount, feeConfig.feePercentage); - if (_token == address(0)) { - require(msg.value == fee, "FC: Not enough HBAR to pay fee"); - Address.sendValue(payable(feeConfig.receiver), fee); - } else { - require(IERC20(_token).balanceOf(msg.sender) >= fee, "FC: Insufficient token balance"); - SafeHTS.safeTransferToken(_token, msg.sender, feeConfig.receiver, int64(uint64(fee))); - } + require(IERC20(_token).balanceOf(msg.sender) >= fee, "FC: Insufficient token balance"); + SafeHTS.safeTransferToken(_token, msg.sender, feeConfig.receiver, int64(uint64(fee))); } /** @@ -91,7 +86,6 @@ abstract contract FeeConfiguration is AccessControl { * @param _feePercentage The fee percentage. */ function _updateFeeConfigInternally(address _receiver, address _token, uint256 _feePercentage) private { - require(_feePercentage > 0 && _receiver != address(0), "FC: Invalid fee config data"); require(_feePercentage < BASIS_POINTS, "FC: Invalid fee"); feeConfig.receiver = _receiver; feeConfig.token = _token; @@ -105,7 +99,7 @@ abstract contract FeeConfiguration is AccessControl { * @param _amount The amount of the transfer. * @param _feePercentage The fee percentage. */ - function _calculateFee(uint256 _amount, uint256 _feePercentage) private pure returns (uint256) { + function _calculateFee(uint256 _amount, uint256 _feePercentage) internal pure returns (uint256) { require(_amount * _feePercentage >= BASIS_POINTS, "FC: Too small amount to consider fee"); return (_amount * _feePercentage) / BASIS_POINTS; } diff --git a/contracts/erc4626/Vault.sol b/contracts/erc4626/Vault.sol index 602fbdf..046dcd8 100644 --- a/contracts/erc4626/Vault.sol +++ b/contracts/erc4626/Vault.sol @@ -13,8 +13,6 @@ import {SafeTransferLib} from "./SafeTransferLib.sol"; import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; -import {IPyth} from "@pythnetwork/pyth-sdk-solidity/IPyth.sol"; - import "../common/safe-HTS/SafeHTS.sol"; import "../common/safe-HTS/IHederaTokenService.sol"; @@ -448,6 +446,32 @@ contract HederaVault is IERC4626, FeeConfiguration, Ownable, ReentrancyGuard { return (_startPosition, rewardTokensSize); } + /** + * @dev Returns all rewards for a user with fee considering. + * + * @param _user The user address. + * @return rewards The calculated rewards. + */ + function getUserRewards(address _user) public view returns (uint256[] memory rewards) { + uint256 currentReward; + uint256 currentFee; + uint256 rewardsSize = rewardTokens.length; + for (uint256 i = 0; i < rewardsSize; i++) { + currentReward = (tokensRewardInfo[rewardTokens[i]].amount - + userContribution[_user].lastClaimedAmountT[rewardTokens[i]]).mulDivDown( + 1, + userContribution[_user].sharesAmount + ); + + if (feeConfig.feePercentage > 0) { + currentFee = _calculateFee(currentReward, feeConfig.feePercentage); + rewards[i] = currentReward - currentFee; + } else { + rewards[i] = currentReward; + } + } + } + function calculateReward(uint256 _id) public view returns (uint256 reward) { address token = rewardTokens[_id]; reward = (tokensRewardInfo[token].amount - userContribution[msg.sender].lastClaimedAmountT[token]).mulDivDown( diff --git a/data/deployments/chain-296.json b/data/deployments/chain-296.json index 2bbfdb7..24d76da 100644 --- a/data/deployments/chain-296.json +++ b/data/deployments/chain-296.json @@ -23,7 +23,7 @@ }, "vault": { "HederaVault": "0xe95E635753a8A233cB736c5CB0dF181Bb865a90b", - "VaultFactory": "0xd58b64b0CEa4eB82D0427524Bc56927410E3120a", + "VaultFactory": "0x4097b8cDe36d20E442B59F78f468eBcA16B9482E", "StakingToken": "0x0000000000000000000000000000000000423251", "Share": "0x0000000000000000000000000000000000423255", "RewardToken": "0x0000000000000000000000000000000000423252"