Use delegateCall in contract B to execute contract A. This executes contract A code with contract B storage.
Not sure what deposit does, it seems more like a withdraw to me.
Nonetheless, contract B needs to have enough allowance from contract A then you can call a delegateCall with transfer from contract B to execute transfer from contact A, and this sends the tokens to msg.sender
This is basically the same as when EOA with enough allowance calls a transfer from the contract to itself, the only difference is that you are using another contract instead.
Read these to understand DelegateCall;
Edit after a long time:
- On the ERC-20 constructor give max allowance to contract B
- On deposit do a transferFrom(A, address(this), amount) now B has A amount tokens
- Then do transferFrom(address(this), msg.sender, amount) now B uses the amount of tokens that it just got from A and send it to the msg.sender
PD: Its kinda pointless to sent tokens from A to B and then B to sender. You could simple to a transferFrom(A, msg.sender, amount). B must have max allowance on itself to send the second txn