I use this "buy" function in a smart contract, to receive Eth. for a token. I would like to extend the function, so if the Eth amount in a transaction is higher than X Eth. then send Y% to smart contract owner.
I'm not sure about what would be the best way to do this, so I'm looking for any suggestions.
Thanks in advance :-)
/**
@dev Buy tokens with ether.
@param minPurchaseReturn The minimum number of tokens you will accept.
*/
function buy(uint minPurchaseReturn) public payable {
uint amount = formulaContract.calculatePurchaseReturn(
(tokenContract.totalSupply() - uncirculatedSupplyCount) - tokenContract.balanceOf(this),
(address(this).balance + virtualReserveBalance) - msg.value,
weight,
msg.value);
amount = (amount - ((amount * fee) / 1000000));
//Now do the trade if conditions are met
require (enabled);
require (amount >= minPurchaseReturn);
require (tokenContract.balanceOf(this) >= amount);
//Accounting - so we can pull the fees out without changing the balance
collectedFees += (msg.value * fee) / 1000000;
emit Buy(msg.sender, msg.value, amount);
tokenContract.transfer(msg.sender, amount);
}
if the Eth amount in a transaction is higher than X Eth
- there is noif
in your code, to begin with.