Transfer all tokens from token contract to exchange contract address

I am using remix for testing my smart contracts
ERC20 token Contract

pragma solidity 0.8.4;

contract Saubaan_2{
    
     string  public name = "Saubaan 2";
    string  public symbol = "SBN";
    uint256 public decimals = 18 ;
    uint256 public totalSupply = 1000000000000000000000000;

    event Transfer(
        address indexed _from,
        address indexed _to,
        uint256 _value
    );

    event Approval(
        address indexed _owner,
        address indexed _spender,
        uint256 _value
    );

    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;

    constructor() {
        balanceOf[msg.sender] = totalSupply;
    }

    function transfer(address _to, uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);

        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

       emit Transfer(msg.sender, _to, _value);

        return true;
    }

    function approve(address _spender, uint256 _value) public returns (bool success) {
        allowance[msg.sender][_spender] = _value;

       emit Approval(msg.sender, _spender, _value);

        return true;
    }

    function transferFrom(address _from, address _to, uint256 _value) public payable returns (bool success) {
        require(_value <= balanceOf[_from]);
        require(_value <= allowance[_from][msg.sender]);

        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;

        allowance[_from][msg.sender] -= _value;

       emit Transfer(_from, _to, _value);

        return true;
    }
}

My Exchange contract

pragma solidity 0.8.4;

import "./Saubaan_2.sol";
 
contract  MySwap  {
    string public name = "MySwap Ultimate Exchange";
    Saubaan_2 public token;
    uint public rate = 100;

    event TokenPurchased(
        address  account,
        address token,
        uint amount,
        uint rate
         
    ); 
    
     event TokenSold(
        address  account,
        address token,
        uint amount,
        uint rate
         
    ); 
  
 function buyTokens() public  payable  {
     // Calculate the number of tokens to buy
     uint tokenAmount = msg.value*rate;

     // Require that myswap has enough tokens
    require(token.balanceOf(address(this)) >= tokenAmount);
    // Transfer tokens to the user
     token.transfer(msg.sender, tokenAmount );

    // Emit an event
     emit TokenPurchased(msg.sender, address(token), tokenAmount, rate);

 }
 function sellTokens(uint _amount) public payable {
     //User cant sell more tokens than they have
     require(token.balanceOf(msg.sender) >= _amount);
     //Calculate the amount of Ether to redeem
   uint etherAmount = _amount / rate;
   // Require MySwap has enough ether
   require(address(this).balance >= etherAmount);
     //perform sale
     token.transferFrom(msg.sender, address(this), _amount);
   payable(msg.sender).transfer(etherAmount);
   
   //Emit an event
   emit TokenSold(msg.sender, address(token), _amount, rate);

 }
    
}

I want to send all the tokens from my ERC20 token to the Exchange contract address to create a liquidity pool
Please help Thanks in advance

2 Likes