# GnoLend
- Github: github.com/stefann-01
- Email: st.nikolic01@gmail.com
- LinkedIn: linkedin.com/in/stefann01
- X: x.com/stefann__01
## Project summary
[GnoLend](https://github.com/gnoverse/GnoLend) is the first lending protocol built using Gnolang, implementing financial primitives for decentralized lending and borrowing. The protocol features lending markets with configurable parameters, variable interest rate models, collateralized borrowing with health monitoring, and liquidation mechanisms for undercollateralized positions. It employs a shares-based accounting system to track user positions, calculates interest based on utilization metrics, and maintains system solvency through real-time risk assessment.
For price determination, GnoLend integrates with [Gnoswap](https://github.com/gnoswap-labs/gnoswap)'s liquidity pools, using them as price oracles in the absence of dedicated oracle infrastructure. This approach enables the protocol to obtain reliable price data directly from on-chain sources without requiring external oracle networks, demonstrating how essential financial primitives can be implemented within the current gno.land ecosystem.
The system calculates borrowing capacity based on collateral values derived from Gnoswap pool prices. This integration creates a self-contained lending solution that maintains the security guarantees of the underlying blockchain while providing the necessary infrastructure for expanding DeFi capabilities on gno.land.
### Goals and deliverables
**Core Refactoring**
Update codebase to match recent changes in Gno and Gnoswap. Improve structure, fix inconsistencies, and complete unfinished components.
* Codebase Update: Align the existing codebase with recent architectural and functional changes in the Gno (CrossRealms) and Gnoswap protocol (updates introduced after the [commit 5774424](https://github.com/gnoswap-labs/gnoswap/commit/5774424d0c6e83c13fec2fc146a906e10ac75285)).
* Code Maintenance: Refactor and reorganize code (e.g., periphery calls, reusable logic extraction, constants cleanup, `onBehalf` support, LLTV/IRM checks fixes, market ID creation refactor, package separation)
**Flashloans Implementation**
Implement logic for uncollateralized loans within single transactions.
* Borrow any amount without collateral, as long as it's returned in the same transaction
* Execute complex operations like arbitrage or collateral swaps in one atomic transaction
* Fail-safe mechanism - if the borrowed amount isn't returned, the entire transaction reverts
**Governance Implementation**
Implementation of the [Common DAO](https://github.com/gnolang/gno/pull/3882) Governance mechanisms for protocol parameter updates
* Customized version of the Common DAO package following [AtomOne Constitution specifications](https://github.com/atomone-hub/genesis/blob/main/CONSTITUTION.md#section-4a-common-dao-spec)
* Governance token enabling holders to create proposals and cast votes
* Defined tokenomics for distribution and participation requirements
* Direct contract integration for automatic parameter updates
* Configurable parameters for interest rates, liquidation thresholds, and protocol fees
* Emergency controls and time-locked parameter changes for security
**Testing & Optimization**
* Tests: Comprehensive test coverage for all smart contract functionality
* Gas Optimization: Optimize code for efficient gas usage
* Deployment Scripts: Automate contract deployment
**Frontend Development**
Develop full-featured web interface for protocol usage.
* Custom Frontend: Dedicated web interface for the lending protocol, including:
* Market overview dashboard
* Position management interface
* Risk monitoring tools
* Governance Managment interface etc.
* Contract Integration: Connect frontend with contracts and refine interactions for reliability and precision
* Gnoweb UI: Build a extensive Gnoweb interface covering full protocol functionality
**Documentation**
Deliver complete documentation for users, developers, and contributors.
* User Docs: Provides guides for protocol interaction, including market creation, position management for lenders and borrowers, liquidation procedures etc.
* Technical Docs: Covers protocol architecture, smart contract interfaces, integration guides, event handling, security best practices, contract interactions, testing procedures etc.
* Protocol Docs: Outlines the economic model, risk parameters, interest rate models, liquidation procedures, governance mechanisms etc.
### Impact on gno.land’s developer ecosystem
As one of the pioneering projects to adopt [Common DAO](https://github.com/gnolang/gno/pull/3882) as governance, GnoLend will help advance governance standards within the ecosystem while serving as a practical implementation reference for other developers. This will promote broader adoption of standardized governance mechanisms on gno.land, strengthening the community-driven development approach.
The protocol will offer a dual-interface approach to user experience, providing both a comprehensive custom UI for advanced users and a minimal Gnoweb UI for simplicity. GnoLend will be one of the most sophisticated dApps fully functional through Gnoweb, demonstrating that complex financial applications can operate effectively using gno.land's native interface despite its minimalist design. This showcases Gnoweb's potential to replace traditional UIs for even complex DeFi applications.
By implementing financial primitives that integrate with existing ecosystem components like Gnoswap, GnoLend demonstrates how developers can build advanced applications even with current infrastructure limitations. This approach of creating composable DeFi building blocks encourages developers to construct interdependent systems, accelerating the maturation of gno.land's DeFi ecosystem.
Our vision is to position GnoLend as a widely adopted lending protocol — comparable in utility and importance to similar protocols on other blockchain ecosystems. By doing so, we aim not only to advance the use of DeFi on gno.land but also to contribute to the expansion and diversification of its broader community.
### Timeline and milestones
The work will be divided between me and @matijamarjanovic, with clear areas of focus but room for collaboration where tasks intersect.
The following is a rough estimate of my project responsibilities, organized by weekly milestones and deliverables. The entire project is expected to take approximately **2 months** to complete. Some tasks will span multiple weeks based on complexity and potential challenges that may arise during development.
**Week 1–2 : Core Refactoring**
Update codebase to match recent changes in Gno and Gnoswap. Improve structure, fix inconsistencies, and complete unfinished components.
* **Codebase Update:**
The current implementation was built on outdated versions of Gno and Gnoswap, which have since introduced significant changes.
The first step will be to identify all breaking changes and incompatibilities, then update and fix the codebase as needed to ensure it works correctly with the latest versions of Gno and Gnoswap.
* **Code Maintenance:**
- **Periphery Calls**: Implement helper library, intended for external integrators, exposing read-only getters that reflect expected values after interest accrual.
- **Reusable Logic Extraction**: Refactor duplicated logic into shared internal functions. Current implementation is proof-of-concept level with minimal modularity and poor readability.
- **Constants Cleanup**: Centralize scattered constants into a structured module for easier maintenance.
- **`onBehalf` Support**: Add missing logic for acting on behalf of other users in key flows (e.g., borrowing, repaying), commonly expected in lending protocols.
- **LLTV/IRM Checks**: Complete the partial implementation of loan-to-value and interest rate model validation. Introduce whitelisting logic to control which LLTV and IRM configurations are allowed.
- **Market ID Lib Refactor**: Fix current Market ID generation logic to support both `(A collateral, B borrow)` and `(B collateral, A borrow)` market pairs. Current method treats them as identical, preventing valid new markets.
- **Package Separation**: Create clear separation between realms and reusable packages.
**Week 2–3 : Flashloans Implementation**
Implement simple but secure flashloan functionality that enables borrowing without collateral within a single transaction.
* **Entry Point**: Add a Flashloan() function to the core contract to initiate flashloan execution. This function transfers the requested amount to a receiver and triggers a callback.
* **Receiver Interface**: Define a required interface (e.g., IFlashloanReceiver) that includes an OnFlashloan() method, which users must implement to receive and use the borrowed funds.
* **Repayment Enforcement**: After callback execution, verify that the full borrowed amount (plus any protocol fee) has been returned. Revert the entire transaction if the check fails.
* **Atomic Execution**: Ensure the entire flashloan logic executes within a single transaction. No state changes should persist if repayment conditions aren’t met.
* **Reentrancy Protection**: Implement reentrancy guards to prevent malicious nested calls during the flashloan lifecycle.
* **Mock Receiver**: Create a mock example to test repayment logic, failure cases, and realistic usage like arbitrage or collateral swaps.
**Week 3–4: DAO Ownership Integration and Governance Token**
Governance will be based on the [Common DAO](https://github.com/gnolang/gno/pull/3882) framework, allowing protocol parameters to be updated through on-chain proposals.
My focus will be on implementing the governance token along with its tokenomics and exposing modifiable parameters to the Governance ownership.
* **Governance Control Integration**: Identify all protocol parameters intended for governance control and expose them via setter functions. Wrap each setter with access control that only allows execution through DAO ownership (i.e., proposals passed and executed by the DAO contract).
* **Governance Token**: Implement a grc20 governance token. Configure basic transfer logic and integrate with the DAO for voting power tracking. The token will be used for proposal creation and voting, with balances determining influence.
* **Tokenomics**: Define parameters for total supply, initial minting, and allocation logic. Set thresholds for proposal submission and quorum based on token balances. Integrate with DAO modules to ensure token balances are correctly read and used during proposal lifecycle.
**Week 4–6 : Testing & Optimization**
This phase focuses on validating protocol logic through tests, reducing gas usage where possible, and preparing automated deployment flows.
* **Tests**:
- Write unit tests and filetests covering all protocol features, including normal operations, edge cases, and failure scenarios.
- Include Makefile-based test flows for better development experience.
- Use mocks to emulate protocol components and behaviors that would be difficult or impractical to test directly (e.g., IRM mock, flashloan callback mock).
- Structure tests clearly to support future maintenance and feature extensions.
* **Gas Optimization**:
- Review contract logic and storage patterns to identify inefficiencies.
- Apply standard optimization techniques (e.g., reduce storage writes, consolidate logic).
* **Deployment**:
- Create Makefile-based deployment scripts for all protocol modules and dependencies.
- Structure deployment into reusable targets (e.g., tokens, libraries, core contracts, governance).
- Enable selective redeployments and support for multiple environments (local, portal-loop, testnet).
**Week 6–7 : Frontend Development (Contract Integration)**
This phase covers collaboration with @matijamarjanovic on connecting the custom frontend to deployed contracts.
My focus will be on handling all interactions and fixing issues that come up during integration.
* Ensure correct input/output handling for all required flows.
* Adjust contracts or integration logic as needed to resolve issues found during connection.
* Iterate until full feature set works reliably through the frontend.
**Week 7–8 : Documentation**
Writing clear and complete documentation for users, developers, and contributors.
* **User Docs**:
Write step-by-step guides for interacting with the protocol.
* Market creation, lending, borrowing, repayments, and liquidations
* Examples with real numbers, screenshots, and common troubleshooting issues
* Integration with Gnoswap pools and token management
* **Technical Docs**:
Document contract architecture and module structure.
* Market/Position structs, Interest Rate Models, Price Oracle integration
* Core lending functions, collateral management, liquidation system
* Event system and integration examples
* **Protocol Docs**:
Explain the economic model and risk parameters.
* Interest rate calculation, fee structure, liquidation incentives
* LLTV ratios, collateral requirements, market risk management
* **Governance & Tokenomics**:
Document governance structure and token mechanics.
* Token utility, staking mechanisms, voting power calculation
* Governance proposals, voting periods, execution process
* Token distribution, emission schedule, economic incentives
* Treasury management, fee distribution, protocol revenue
## Contributions or related work for gno.land (if applicable)
Most of my contributions to gno.land were made through my participation in the *Student Contributors Program (RAF cohort)* and are documented in the following issues:
- [Hacker Space Journey – Issue #94](https://github.com/gnolang/hackerspace/issues/94)
- [SCP Updates – Issue #39](https://github.com/gnolang/meetings/issues/39)
## Why are you and your team well-suited for this project?
Interest in Decentralized Finance is what initially drew me into blockchain technology. For the past two years, I’ve been researching, comparing, and using various DeFi protocols across multiple ecosystems as a personal hobby.
This project is a great opportunity to combine that interest with the experience we gained during the *SCP*. The focus on DeFi and token standards has been evident through our contributions:
- [Fomo3D](https://gno.land/r/stefann/fomo3d) - A game with financial mechanics where players earn dividends proportional to their key holdings. Implements share-based accounting for yield distribution.
- [grc721 Fix](https://github.com/gnolang/gno/pull/3495) - Fixed critical extension issues, enabling the use of NFTs with metadata functionality.
- [grc20 Issues](https://github.com/gnolang/gno/issues/3692) - Documentation of grc20 standard issues. Identifying problems with interface consistency, extension mechanisms, and token factory limitations.
- [TokenHub](https://gno.land/r/matijamarjanovic/tokenhub) - Central registry for all GRC token standards. Enables users to track their complete token portfolio using only the Gnoweb interface.
- [GnoXchange]() - Decentralized exchange that features both AMM and peer-to-peer trading, with P2P moudule supporting listings for both grc20 and grc721 tokens.
- [grc721 Remake](https://github.com/gnolang/gno/pull/3973) - Redesigned grc721 standard aligned with grc20 architecture. PR adresses existing issue by introducing a hook-based extensibility to customize token behavior without modifying the standard implementation.
- [GnoLend PoC](https://github.com/gnoverse/GnoLend) - Proof-of-concept demonstrating the viability of this project.
Our experience with Gno/gno.land's features and constraints, combined with our DeFi understanding, positions us to expand the range of tools and opportunities for future mainnet users by creating a lending solution specifically designed for the gno.land ecosystem.
## Referrals or examples of past work
Additional examples of my work and experience are available in my CV:
[View CV](https://drive.google.com/file/d/.1jFoRnc-kL1SBUES7sCZxELz9UIZ9oNMH/view?usp=sharing)