Deployed contract address: 0x2AEba18dB80D44c41ba6339cb9E0FCAef7A9766B
The GasVault is a smart contract implemented in Solidity that allows users to deposit and withdraw GAS tokens (represented as Ether in this example). The contract keeps track of each user's deposit balance and the total amount of GAS tokens deposited by all users.
- Deposit: Users can deposit GAS tokens into the vault.
- Withdraw: Users can withdraw a specified amount of their deposited GAS tokens.
- Exit: Users can withdraw their entire balance of GAS tokens from the vault.
The GasVault
smart contract includes the following key functionalities:
- Deposit: Allows users to deposit Ether into the contract.
- Withdraw: Allows users to withdraw a specified amount of their Ether balance from the contract.
- Exit: Allows users to withdraw their entire balance from the contract.
deposit()
: Deposits GAS tokens (Ether) into the vault. Reverts if the deposit amount is zero.withdraw(uint256 amount)
: Withdraws a specified amount of GAS tokens from the vault. Reverts if the withdrawal amount exceeds the user's balance.exit()
: Withdraws the user's entire balance of GAS tokens. Reverts if the user's balance is zero.
Deposited(address indexed addr, uint256 amount)
: Emitted when a user deposits GAS tokens into the vault.Withdrawn(address indexed addr, uint256 amount)
: Emitted when a user withdraws GAS tokens from the vault.
To get started with this repository, you need to have Foundry installed.
-
Clone the repository:
git clone https://github.com/your-username/gas-vault.git cd gas-vault
-
Install dependencies:
forge install
-
Build smart contract:
forge build
The repository includes comprehensive tests for the GasVault smart contract. The tests are written using Foundry's testing framework.
-
testDeposit: Tests the deposit functionality to ensure that deposited Ether is correctly recorded.
-
testWithdraw: Tests the withdraw functionality to ensure that users can withdraw their deposited Ether.
-
testExit: Tests the exit functionality to ensure that users can withdraw their entire balance.
-
testFailDepositZeroAmount: Tests that depositing zero Ether reverts as expected.
-
testFailWithdrawMoreThanBalance: Tests that attempting to withdraw more than the available balance reverts.
-
testFailExitWithZeroBalance: Tests that attempting to exit with zero balance reverts.
-
testMultipleDeposits: Tests multiple deposits by the same user to ensure correct balance tracking.
-
testWithdrawPartialAmount: Tests withdrawing a partial amount from the user's balance.
forge test
To deploy the GasVault contract on a local or public Ethereum network:
Configure your deployment script: Ensure you have the correct network configurations in place. Deploy using Foundry: You can deploy your contract using Foundry's forge create command or by writing a deployment script.
sample deployment command
forge create GasVault --private-key <YOUR_PRIVATE_KEY> --rpc-url <RPC_URL>