Vault 1
alcueca opened this issue · comments
Alberto Cuesta Cañada commented
Users can send a given Token
to a Vault
contract, that records their balance, only that owner can retrieve that token. Think of it as a multi-user safe.
To complete this you will need two contracts, one of them an ERC20 token that will be moved around, and another one the Vault that will store it for the users.
There are a couple of patterns to achieve this, but I suggest that you take the traditional approach:
- Vault should import the IERC20 interface, take the
Token
address in theVault
constructor, and cast it into an IERC20 state variable. - The user
approve
theVault
to takeToken
from them in one transaction. - The user calls a function that instructs the
Vault
to take from them an amount ofToken
, which now belongs to theVault
, in exchange, theVault
records the user'sdeposit
. - Whenever the user feels like it, it can
withdraw
its deposit. TheToken
is returned, and theVault
updates its user records.