syncastra
syncastra

Reputation: 122

How to add tokenomics to a ERC20 token?

I have taken different courses and even tho they explain how to make a token I haven't been able to learn how to implement tokenomics.

For example fees for transactions, burning to LP etc...

I leave a link to the openzeppelin standard

Would be great to have some more detailed examples on it.

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol

Upvotes: 1

Views: 848

Answers (1)

NuMa
NuMa

Reputation: 608

What you are looking for is to make a custom _transfer() method by overriding the one provided in the OpenZeppelin ERC20 standard.

You can check with the "OXB" (oxbull.tech) token, which implements this type of fee, but basically you just take tokens from the sender before sending them to the receiver, and once you are done charging the fees you can send the remaining tokens to the receiver.

An example would be:

function _transfer(address sender, address recipient, uint256 amount) private {
    require(sender != address(0), "BEP20: transfer from the zero address");
    require(balanceOf(sender) >= amount, "BEP2': not enough balance");
    
    uint256 tokensToBurn = amount.mul(burningFee).div(100);
    amount = amount.sub(tokensToBurn);

    balances[sender] = balances[sender].sub(amount);

    _burn(sender, tokensToBurn);
    balances[recipient] = balances[recipient].add(amount);
    
}

Options of what you can do are infinite. Hope this is helpful.

Upvotes: 2

Related Questions