I’m having trouble dealing with the fact that msg.sender is the contract address when my smart contract calls a function from another contract’s interface. I want to create a basic smart contract that can do simple operations like swapping tokens through a DEX, or withdrawing/depositing LPs. However, these functions all reference msg.sender, so if the user is not the one directly calling them nothing happens- my contract doesn’t hold any tokens/LPs to swap.
I tried to get around this by using delegatecall. However this seems to be mainly used when working with proxy contracts. Or, you call contract C1, C1 calls C2, C2 calls C3. You want msg.sender in C3 to be C1 not C2, use delegatecall. When trying to use delegatecall in my smart contract to call, say a swap function, the transaction succeeds but execution fails.
How can I get around this issue of msg.sender being my contract address? Should I somehow approve my contract to spend my tokens? There has got to be some way to do this. Otherwise things like arbitrage using flashloans (my main motivation) would not be possible?