This project implements a basic Decentralized Finance (DeFi) Lending Platform using Clarity smart contracts on the Stacks blockchain. The platform allows users to deposit and withdraw STX tokens, borrow from the liquidity pool, and repay their loans.
- Deposit STX tokens
- Withdraw STX tokens
- Borrow STX tokens
- Repay borrowed STX tokens
- Check account balance
- Check borrowed amount
- View total platform liquidity
- Stacks CLI
- Clarinet for local development and testing
-
Clone the repository:
git clone https://github.com/yourusername/defi-lending-platform.git cd defi-lending-platform -
Install dependencies:
clarinet requirements -
Test the smart contract:
clarinet test
The main smart contract (defi-lending.clar) contains the following public functions:
(deposit (amount uint)): Deposit STX tokens into the platform(withdraw (amount uint)): Withdraw STX tokens from the platform(borrow (amount uint)): Borrow STX tokens from the liquidity pool(repay (amount uint)): Repay borrowed STX tokens
And the following read-only functions:
(get-balance (account principal)): Get the deposited balance of an account(get-borrows (account principal)): Get the borrowed amount of an account(get-total-liquidity): Get the total liquidity available in the platform
To deploy the smart contract to the Stacks testnet:
- Make sure you have STX tokens in your testnet wallet.
- Update the
Clarinet.tomlfile with your deployment settings. - Run the deployment command:
clarinet deploy --testnet
After deployment, users can interact with the contract using the Stacks CLI or by integrating it into a web application using the Stacks.js library.
Example of calling the deposit function using the Stacks CLI:
stx call_contract_func -t <CONTRACT_ADDRESS> -c defi-lending -f deposit -a <AMOUNT_IN_USTX> --testnet
- Implement interest rate calculations
- Add collateralization requirements
- Develop liquidation mechanisms
- Support multiple token types
- Introduce governance features
Contributions are welcome! Please feel free to submit a Pull Request.
Blessing Eze