How to accept a Token Like USDT Instead of BNB/ETH for my own Token Exchange?

Hello Everyone :slight_smile:

I have a project and would like to write my own exchange. The exchange already works on the basis of BEP20. So I can exchange my own token for BNB with a fixed exchange rate. But now I would like to change it so that the buyer does send USDT for example insteadt of BNB.

Thank you in advance :slight_smile:
Best Regards

A bit more code/infos would be nice but here a 1:1 ratio solution:


// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract MyWrapper {

    using SafeERC20 for IERC20;


    function swap(address tokenA, address tokenB, uint amount) external {
        //You wrote exchange so I guess it should go both ways?
        //tokenA means the user gives that token in and want to get tokenB
        IERC20(tokenA).safeTransferFrom(msg.sender, address(this), amount);
        IERC20(tokenB).safeTransfer(msg.sender, amount);