KipuBank is a smart contract built on the Ethereum blockchain as part of a Web3 developer assessment. This project demonstrates fundamental Solidity concepts, security best practices, and a professional development workflow using Foundry.
The contract allows users to:
- Deposit native ETH into a personal vault.
- Withdraw ETH from their vault, up to a fixed, per-transaction limit.
- Operate within a global deposit cap for the entire bank.
This project emphasizes security, readability, and clear documentation, adhering to the "Checks-Effects-Interactions" pattern and using custom errors and modifiers.
This project uses the Foundry framework. The main contract is located in the /contracts directory.
/contracts: Contains theKipuBank.solsmart contract./test: Contains the complete test suite (KipuBank.t.sol)./script: Contains the deployment script (DeployKipuBank.s.sol).
To get a local copy up and running, follow these simple steps.
You will need the following tools installed on your machine:
-
Clone the repository:
git clone [https://github.com/](https://github.com/)[SEU_USUARIO_GITHUB]/[NOME_DO_REPOSITORIO].git cd [NOME_DO_REPOSITORIO] -
Build the project: This command will compile the smart contracts.
forge build
-
Run the tests: This command will run the entire test suite located in the
/testfolder.forge test -vv
The contract is designed to be deployed on a testnet (e.g., Sepolia).
-
Set up your environment: Create a
.envfile in the root directory and add the following variables:export SEPOLIA_RPC_URL="YOUR_ALCHEMY_OR_INFURA_RPC_URL" export PRIVATE_KEY="0xYOUR_WALLET_PRIVATE_KEY" export ETHERSCAN_API_KEY="YOUR_ETHERSCAN_API_KEY" # Constructor Arguments (in wei) export BANK_CAP=100000000000000000000 export WITHDRAWAL_LIMIT=1000000000000000000 -
Run the deployment script: Load the environment variables and run the deployment script.
source .env forge script script/DeployKipuBank.s.sol:DeployKipuBank --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast --verify -vvvv
The KipuBank contract has the following core functions:
deposit(): (Payable) Allows any user to deposit ETH. Reverts if the amount is zero or if the bank cap is exceeded.withdraw(uint256 _amount): Allows a user to withdraw ETH from their balance. Reverts if the amount is zero, exceeds the withdrawal limit, or if the user has insufficient funds.getBalanceOf(address _user): (View) Returns the current ETH balance of any specified user address within the contract.i_withdrawalLimit: (Public View) Shows the immutable withdrawal limit per transaction.i_bankCap: (Public View) Shows the immutable total bank cap.
- Heitor Valim
- GitHub:
https://github.com/heitorvalim7