Hi guys, I'm trying to create a smart contract that receives the buying and selling fees from another smart contract, so when a user calls the "distribute" function, the contract exchanges these received tokens for USDT on pancakeswap and then sends them

interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);

interface IMillionaireTracker {
function getMillionaires() external view returns (address memory);

interface IPancakeRouter02 {
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address calldata path,
address to,
uint deadline
) external returns (uint memory amounts);

function WETH() external view returns (address);


contract CashHand_Distributor {
address public constant cashhand = 0xb205385464fFa3238F9Ea81E39991F5F3109865b; // cashhand Token Address
address public constant usdt = 0x55d398326f99059fF775485246999027B3197955; // USDT Token Address
address public constant pancakeRouter = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // PancakeSwap Router Address
address public constant WBNB = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c; // WBNB Token Address (Wrapped BNB)
address public trackerAddress = 0xb205385464fFa3238F9Ea81E39991F5F3109865b; // Tracker Address
address public constant WBNB_USDT_PAIR = 0x16b9a82891338f9bA80E2D6970FddA79D1eb0daE; // PancakeSwap WBNB-USDT Pair Address
address public owner;

constructor() {
    owner = msg.sender;

modifier onlyOwner() {
    require(msg.sender == owner, "Only the owner can call this function");

function distribute() external {
// Get the current token balance in the contract
IERC20 token = IERC20(cashhand);
uint256 balance = token.balanceOf(address(this));
require(balance > 0, "Insufficient balance for distribution");

// Exchange tokens for USDT using the cashhand -> WBNB -> usdt route

// Get updated USDT balance after switching
uint256 usdtBalance = IERC20(usdt).balanceOf(address(this));

// Get Millionaire Tracker
IMillionaireTracker tracker = IMillionaireTracker(trackerAddress);

// Get the list of millionaires
address[] memory millionaires = tracker.getMillionaires();
uint256 totalMillionaires = millionaires.length;
require(totalMillionaires > 0, "No millionaires found");

// Calculate the amount of USDT to be distributed to each millionaire
uint256 valueByMillionaire = usdtBalance / totalMillionaires;

// Distribute USDT to millionaires
for (uint256 i = 0; i < totalMillionaires; i++) {
    require(IERC20(usdt).transfer(millionaires[i], valueByMillionaire), "Transfer failed");


// Set exchange path: cashhand -> WBNB -> usdt
function swapCashHandForUSDT(uint256 amount) internal {
address[] memory path = new address[](3);
path[0] = cashhand;  
path[1] = WBNB;       
path[2] = usdt;       

// Approve Router to spend input tokens (cashhand)
IERC20(cashhand).approve(pancakeRouter, amount);

// Perform the swap using swapExactTokensForTokens
IPancakeRouter02 router = IPancakeRouter02(pancakeRouter);