A DeFi lending and staking DApp inspired by Aave, built with Solidity and Foundry.
The project explores core DeFi concepts such as borrowing, collateral management, staking, smart-contract interactions, and Solidity-based testing.
⚠️ Educational Project: This project is intended for learning and experimentation. It has not been audited and should not be used with real funds.
The goal of this project is to build a structured DeFi protocol where users can interact with smart contracts for lending/borrowing and staking functionality.
The project currently includes:
- Borrowing functionality
- Staking functionality
- Solidity smart contracts
- Foundry-based testing
- Local Ethereum development with Anvil
- Deployment scripts
- Gas analysis and snapshots
The repository is built using Foundry, which provides Forge for testing, Cast for blockchain interaction, Anvil for a local Ethereum node, and Chisel as a Solidity REPL.
DEFI-DApp/
│
├── Contracts/
│ ├── Borrow.sol
│ ├── Staking.sol
│ └── libraries/
│
├── src/
│ └── Counter.sol
│
├── test/
│ ├── Borrow.t.sol
│ └── Counter.t.sol
│
├── script/
│ └── ...
│
├── lib/
│ └── ...
│
├── .github/
│ └── workflows/
│
├── foundry.toml
├── foundry.lock
├── package.json
└── README.md
The current repository contains dedicated Borrow.sol and Staking.sol contracts and a Borrow.t.sol test file.
This project is designed to explore several important DeFi concepts:
Users can interact with the borrowing system through smart contracts, with the protocol managing the associated lending/borrowing logic.
The project also contains a staking contract for exploring how users can lock assets in a smart contract and participate in a staking mechanism.
The project separates protocol functionality into different contracts rather than putting the complete protocol into a single contract.
This makes the system easier to develop, test, and extend.
Testing is written in Solidity using Foundry/Forge.
Run the complete test suite:
forge testRun tests with detailed traces:
forge test -vvvvRun only the borrowing tests:
forge test --match-path test/Borrow.t.solRun a specific test:
forge test --match-test testFunctionNameGenerate a gas report:
forge test --gas-reportRetry previously failed tests:
forge test --rerunFoundry supports fuzz testing by automatically generating different inputs for Solidity test functions.
Example:
function testFuzz_Borrow(uint256 amount) public {
amount = bound(amount, 1, 100 ether);
// Test borrowing logic
}Increase the number of fuzz runs:
forge test --fuzz-runs 10000Fuzz testing helps discover edge cases that may not be covered by manually selected inputs.
DeFi protocols often depend on timestamps.
Foundry cheatcodes can be used to manipulate blockchain time during testing:
vm.warp(block.timestamp + 7 days);This makes it possible to test:
- Staking periods
- Loan deadlines
- Interest calculations
- Expiration conditions
- Time-based withdrawals
Generate a gas report:
forge test --gas-reportCreate a gas snapshot:
forge snapshotGas analysis is useful when optimizing DeFi contracts because transaction costs can have a significant impact on protocol usability.
- Solidity
- Foundry
- Forge
- Anvil
- Cast
- OpenZeppelin where applicable
- Ethereum / EVM
Install Foundry before starting.
Then clone the repository:
git clone https://github.com/mohit-solidity/DEFI-DApp.git
cd DEFI-DAppInstall dependencies:
forge installBuild the contracts:
forge buildRun the tests:
forge testStart a local Ethereum node:
anvilYou can then deploy contracts against the local Anvil network using a Foundry deployment script.
Example:
forge script script/Counter.s.sol:CounterScript \
--rpc-url http://127.0.0.1:8545 \
--broadcastReplace the script and deployment parameters with the appropriate protocol deployment script when deploying the DeFi contracts.
forge buildforge testforge fmtforge snapshotanvilcast <subcommand>forge --help
anvil --help
cast --helpThese are the standard Foundry workflows currently documented in the repository.
This project is not production-ready and has not undergone a professional smart-contract audit.
Before using a DeFi protocol with real funds, additional work would be required, including:
- Comprehensive unit testing
- Fuzz testing
- Invariant testing
- Static analysis
- Reentrancy analysis
- Access-control review
- Oracle manipulation testing
- Economic/security analysis
- Professional auditing
This project is intended to help develop practical experience with:
- Solidity smart-contract development
- DeFi protocol architecture
- Lending and borrowing mechanisms
- Staking mechanisms
- Foundry
- Forge testing
- Fuzz testing
- Solidity cheatcodes
- Gas optimization
- Local blockchain development
- Smart-contract security
Mohit Sharma
GitHub: https://github.com/mohit-solidity
If you find this project useful for learning Solidity and DeFi development, consider giving the repository a ⭐.
Disclaimer: This project is for educational purposes only. Do not deposit real funds or use the contracts in production without thorough testing and professional security auditing.