Hi
I want to collect fees before each transaction is sent. In the first example, I am sending ETH and the fees are added to the contract. If I sent ERC20 tokens and check the contract value it is always 0. Any idea what I am doing wrong here?
works
function sendETH(
address _token,
address payable _to,
address _orderBookUID,
uint256 _orderID,
bytes32[2] memory _title,
uint256 _deadline
) external payable override lock ensure(_deadline) {
require(msg.sender != _to, "BPR::Now allowed send yourself");
require(
msg.value > 0,
"BPR::sendETH amount not > 0"
);
uint256 _amountInMinusFee = PayLibrary.getAmountOut(msg.value);
_to.transfer(_amountInMinusFee);
emit Transfer(msg.sender, _to, msg.value);
}
not works
function sendToken(
address _token,
address _to,
address _orderBookUID,
uint256 _orderID,
uint256 _amount,
bytes32[2] memory _title,
uint256 _deadline
) external override lock ensure(_deadline) returns (bool) {
IERC20 token = IERC20(_token);
require(msg.sender != _to, "BPR::Now allowed send yourself");
require(_amount > 0, "BPR::sendToken amount not > 0");
uint256 _amountInMinusFee = PayLibrary.getAmountOut(_amount);
token.transferFrom(msg.sender, _to, _amountInMinusFee);
emit Transfer(msg.sender, _to, _amount);
return true;
}
Collecting Fees PayLibrary.sol
function getAmountOut(uint256 _amountIn)
internal
pure
returns (uint256 amountOut)
{
require(_amountIn > 0, "AmountOut: INSUFFICIENT_AMOUNT");
uint256 amountInWithFee = _amountIn * (990);
return amountInWithFee / 1000;
}