The Vault contract is a Solidity smart contract designed to enable users to deposit and withdraw ERC20 tokens that are whitelisted on the given contract. This contract includes admin access control so that the current owner of the contract can pause and unpause it, whitelist ERC20 token addresses, as well as transfer ownership of the contract (inherits OpenZeppelins' Ownable contract).
- Deposit and Withdrawal: Users can deposit and withdraw whitelisted ERC20 tokens.
- ERC20 Token Whitelisting: The owner of the contract can whitelist ERC20 token addresses so that users can deposit those given tokens into the Vault.
- Pausing: The owner of the contract can pause or unpause the contract, controlling the access flow to its user-facing functions.
- Access Control: Only the owner of the contract can pause/unpause the contract and whitelist tokens.
- The testing suite was drafted using Foundry. To run it, the Foundry framework should be installed. Refer to the Foundry Book at: (https://getfoundry.sh/)
-
Clone the repository:
git clone [REPOSITORY_URL] cd [REPOSITORY_DIRECTORY]
-
Compile the contract and testing suite:
forge build
To run the testing suite:
forge test
To run a specific test:
forge test --match-contract VaultTest --match-test NAME_OF_TEST
(To check test function calldata stack add the -vvvv
modifier after your test command.)
To check testing coverage:
forge coverage
- User calls
approve(VAULT_CONTRACT_ADDRESS, AMOUNT_TO_APPROVE)
on a whitelisted ERC20 token contract address and approves the amount to deposit to the Vault - User calls
deposit(WHITELISTED_TOKEN_ADDRESS, APPROVED_AMOUNT)
to deposit up to the previously approved amount of whitelisted token - User calls
withdraw(WHITELISTED_TOKEN_ADDRESS, AMOUNT_TO_WITHDRAW)
to withdraw the requested amount of previously deposited token
- Owner calls
whitelistToken(ERC20_ADDRESS)
to whitelist a given ERC20 token address - Owner calls
pause()
to restrict user access flow to the contract - Owner calls
unpause()
to restore user access flow to the contract - Owner calls
transferOwnership(NEW_OWNER)
to give ownership of the contract to a new address