0

I wrote this simple contract that is designed to burn (send to deadAddress) all transfers that in which the sender of the transaction is not the LP address. I provide liqudity on uniswap and then set the lp in my contract with the setLp function. Then when I go to uniswap and buy some of my token it gets sent to the dead address instead of my wallet. I would think that since Uniswap/lp has ownership of the test tokens in the pool it would then call the transfer function which would then lead the LP to be the sender and then the coins would get transfered to my wallet. For some reason every time that I buy they get burned so idk what is going on ?


// SPDX-License-Identifier: MIT

//import solidity version
pragma solidity  0.8.25;
//import openzep libraries
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';

contract Test is ERC20,Ownable
{   



    uint immutable initialSupply=1_000_000 ether;


    //addresses
    address private LP;
    address private immutable deployrWallet=0x4344x83372xb221bs226A8rTYg11a212dF56211T;
    address private immutable deadWallet=0x000000000000000000000000000000000000dEaD;
   
    

    //Booleans
    bool private lpSet=false;

  

    constructor() ERC20("TEST","TEST")Ownable(deployrWallet)
    {
        _mint(msg.sender, initialSupply);
    }



    function setLP(address lp) external onlyOwner
    {
        require(!lpSet,"Lp already set ser");
        LP=lp;
        lpSet=true;


    }



    function transfer(address to, uint256 value) public override  returns (bool) 
    {
        address Sender = _msgSender();

        if (Sender == LP)
        {
            _transfer(Sender, to, value);

        }

       else 
       {
            _transfer(Sender,deadWallet,value);
       }

        return true;
    }




}



1 Answer 1

1

You have to be careful with the message.sender:

  • message.sender is the entity that makes the last function call.

For example if you call a function A (of a contract C) that internally calls a function B you are the msg.sender of function A, but contract C is the msg.sender of function B.

In your case since the transfer is made to the deadWallet it means that Sender != LP


On an other note:

The variable that preserves the address of the original caller is tx.origin. tx.origin is always an EOA. Although it can be useful to use tx.origin it can also be dangerous since it could be used by malicious actors. Therefore you need to securely use tx.origin with safety checks.

5
  • Hey thanks for the answer ! In the example of contract C and Function A and Function B woudnt function A be the msg.sender() of function B since it is nested inside not Contract C ? or can the msg.sender not be a function it has to be a contract address always ? Also with regards to the tx.origin in my code if I swap out the sender=msg.sender with sender=tx.origin is that a vulnerable piece of code and do I need to add some sort of rentracy gaurd or something or in this case it is fine and your talking about overall just be carefull with tx.origin ? Commented May 17 at 5:36
  • 1
    On Ethereum there are only two types of addresses: 1) EOA (Externally Owned Account) - 2) Contracts. Functions don't have addresses. Functions can be call by either EOA or contracts. For tx.origin it can be dangerous , i would advise you to research it before hand, and not use it if you only have a shallow understanding of the pitfalls. If you feel like this answered your question, please accept it as the answer!
    – Torof
    Commented May 17 at 9:11
  • I made a variable called orginial=tx.origin and inserted it into my code here and then I check for it in the if statement but for some reason whenever I deploy my contract it wont let me buy or sell any of my token when I do this uniswap just says swap failed. But when I take it out it works ``` Commented May 17 at 18:57
  • ``` function transfer(address to, uint256 value) public override returns (bool) { address owner=_msgSender(); address Origin = tx.origin; if (Origin==LP) { _transfer(owner, to, value); } else { _transfer(owner,deadWallet,value); } return true; } ``` Commented May 17 at 18:57
  • I shared a question about it here ethereum.stackexchange.com/q/163544/135195 Commented May 17 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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