I have discovered a contract that can buy and sell multiple times within the same transaction. How does that contract work, and where can I find this contract? Thank you. https://etherscan.io/tx/0x4bf9644ebf9f5f44193420005e73f8f04bda15e357619233f018d344f137d103
Looks like it is an arbitrage transaction – changing tokens several times with different paths to get some profit from unbalanced pools. For more information you can google for "mev", "flashbots" and so on, there is a plenty of info including sources of such contracts.
Also you can check https://eigenphi.io/ service for more such transactions (you need to check "arbitrage", not "sandwich")
As for coding contracts with several transfers - it is simple. You just do several calls to several contracts with different calldata