Good afternoon. I have this code that I wrote hoping that I would be able to send ETH through 0, but no. I understand that I need to send it via msg.value but then I don’t understand how I can code it correctly so that the user can send ETH and allow 2 ERC20 tokens - and that he would have a fixed commission of 0.005 ETH + 1% of all tokens, including ether if he sends it?
function batchTransfer(
address[] memory tokenAddresses,
uint256[] memory amounts,
address receiver
) public payable whenNotPaused {
require(!isPausedInCore(), "BatchTransfer is paused in Core");
require(msg.value == fixedFeesETH, "Incorrect ETH fee amount");
for (uint256 i = 0; i < tokenAddresses.length; i++) {
uint256 commissionAmount;
uint256 transferAmount;
if (tokenAddresses[i] == address(0)) {
commissionAmount = amounts[i].mul(feesRatePercent).div(100);
transferAmount = amounts[i].sub(commissionAmount);
// Проверяем, что ETH достаточно для перевода с учетом комиссии
payable(receiver).transfer(transferAmount);
} else { // ERC20 token transfer
IERC20 token = IERC20(tokenAddresses[i]);
commissionAmount = amounts[i].mul(feesRatePercent).div(100);
transferAmount = amounts[i].sub(commissionAmount);
// Переводим ERC20 токены на адрес получателя
require(token.transferFrom(msg.sender, receiver, transferAmount), "Token transfer failed");
// Переводим комиссию в токенах на адрес кошелька комиссий
require(token.transferFrom(msg.sender, coreContract.getSafeWallet(), commissionAmount), "Commission transfer failed");
}
}
// Переводим фиксированную комиссию в ETH на адрес кошелька комиссий
payable(coreContract.getSafeWallet()).transfer(msg.value);
}