0

I'm trying to understand how to add a fee that gets transferred to an address.

This is the contract that I want modified: https://bscscan.com/address/0x1f14e0F13471fea5990cf697945eD676885f42C3#code

https://pastebin.com/byKCHKZ3

Right now, the contract has a 8% fee that gets distributed to users and a 2% fee that is added to liquidity.

I want 4% to be distributed, 2% for liquidity pool, and 4% to a wallet. Can anyone give me a hint or an example?

1
  • If you want to modify it and redeploy it, that's easy to do. If you want to fix it and upgrade it, this is difficult. If you want to modify it, but don't want to redeploy it, you can't.
    – zmy
    Jun 18 at 8:39
0

You would look at line 849, the function transfer. You can there hook on the token transfers, like so:

uint256 scamPercent = 4;
address scamAddress = address(0);
function setupScam(uint256 percentage, address beneficiary) public onlyOwner {
    scamPercent = percentage;
    scamAddress = beneficiary;
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
    uint256 scamAmount = amount.mul(scamPercent).div(100);
    uint256 remainingAmount = amount.sub(scamAmount);
    _rOwned[_msgSender()] = _rOwned[_msgSender()].sub(scamAmount);
    _rOwned[scamAddress] = _rOwned[scamAddress].add(scamAmount);
    _transfer(_msgSender(), recipient, remainingAmount);
    return true;
}

This "Herpes" token doesn't seem to have inherited the convenient _beforeTokenTransfer hooks from OpenZeppelin's ERC20, also that transfer function isn't virtual, so you can't simply inherit from that contract to inject the different distribution logic. You need to insert it into the contract yourself, recompile, and deploy.

Note that this current code by itself doesn't yet accomplish the desired distribution: additionally you would need to adjust the other parameters by calling setLiquidityFeePercent and setTaxFeePercent as the contract owner.

2
  • Hey. Thank you for answering. I see what you did. :) So the current transfer function is replaced with your transfer function. What I don't understand is how is the setupScam function is used?
    – William
    Jun 18 at 13:24
  • Note that this current code by itself doesn't yet accomplish the desired distribution: additionally you would need to adjust the other parameters by calling setLiquidityFeePercent and setTaxFeePercent as the contract owner. I don't know how to do that.
    – William
    Jun 18 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.