https://github.com/hirosystems/platform-template-stx-defi
https://github.com/hirosystems/platform-template-stx-defi
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hirosystems/platform-template-stx-defi
- Owner: hirosystems
- License: mit
- Created: 2024-11-11T20:26:37.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-14T22:26:45.000Z (8 months ago)
- Last Synced: 2025-12-23T06:43:50.205Z (6 months ago)
- Language: Clarity
- Size: 93.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Decenntralized Finance (DeFi) Loans using STX
A DeFi loan utilizes smart contracts to enforce compliance with loan conditions, such as the application of interest rates and the automated distribution of yields on deposited assets.
> **NOTE**: Normally, DeFi loans permit the borrowing of liquidated assets by using cryptocurrency as collateral. However, to simplify and effectively teach the use-case in a straightforward way, this particular DeFi loan example showcases both deposits and lending using the same STX asset.
## Know your Contract
The [stx-defi.clar](/examples/stx-defi/contracts/stx-defi.clar) contract includes the following public functions.
+ `deposit` function for users to deposit STX into the contract
+ `borrow` function for users to borrow STX based on their deposits
+ `repay` function for users to repay their STX loans
+ `get-amount-owed` function to get the total amount owed by the user
+ `claim-yield` function for users to claim their yield based on the pool reserve and their deposits
To add a new contract, use [Clarinet](https://docs.hiro.so/stacks/clarinet).
## Test your contract
You can manually test your contract in the Clarinet console. After entering the console with `clarinet console` you can make contract function calls to verify the protocol functionality:
`(contract-call? .stx-defi deposit u1000)`
`(contract-call? .stx-defi borrow u7)`
`(contract-call? .stx-defi get-amount-owed)`
Alternatively, you can run the unit tests included in the `tests/` folder. From the terminal session, navigate to `/clarity-example/stx-defi` folder, and run `npm test`.