I'm trying to develop a contract to which users would send certain amounts of tokens A and B to the smart contract. Easiest/obvious way to do it would be to do several transactions in this order:
- User calls
approve
for tokenA for an amount of X where the smart contract is the spender - User calls
approve
for tokenB for an amount of Y where the smart contract is the spender - User then calls the smart contract which uses
transferFrom
the user to the smart contract for those amounts
This is however very cumbersome for the user, who has to sign and send 3 different transactions.
Is there a way where the user can call a single function in my smart contract, and the smart contract can transfer those funds from the user directly? I'm thinking something similar to what Uniswap v2 uses:
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
Although probably using delegatecall()
would be more appropiate in this context.
Would this work or would the user still need to set an approval? Any ideas on how could I improve the user experience in this case?