Comprehensive Development of a Money Market Protocol
OMOMO is a groundbreaking money market protocol designed to empower users with advanced financial tools on the NEAR blockchain. Blaize collaborated with OMOMO across three major milestones to build, enhance, and optimize the protocol: Money Market Protocol Development, Limit Orders Implementation, and Leverage Trading Development and Implementation. This unified effort has transformed OMOMO into a leading DeFi hub within the NEAR ecosystem.
The collaboration began with Blaize expanding its Rust expertise to delve into the NEAR ecosystem. Inspired by the community at NEARcon 2021, we introduced a concept for a lending/borrowing protocol during the Nearhack Hackathon in Kyiv, which won a grant prize. Over the following months, we formalized the protocol’s architecture, conducted smart contract audits, and developed a brand identity for OMOMO.
MILESTONE 1: MONEY MARKET PROTOCOL DEVELOPMENT
WHAT WAS THE TASK?
The main task for this milestone was to design and develop a permissionless borrow/lending protocol where all transactions are executed entirely on-chain and managed by smart contracts. The protocol needed to provide users with the ability to:
- Supply and borrow assets in a decentralized manner.
- Retain ownership of leveraged positions through secure and transparent borrowing mechanisms.
- Eliminate DEX fees and slippage for all asset swaps.
- Enable DAO-governed management of asset tiers and protocol parameters to ensure decentralization and adaptability
PROJECT ARCHITECTURE
The architecture for the Money Market Protocol was designed to prioritize modularity, scalability, and security. The core components included:
- Market Contracts: Dedicated contracts to handle specific asset classes. These contracts manage user deposits, borrow requests, and interest calculations for both lenders and borrowers.
- Controller Contract: A centralized module governed by a DAO that facilitates interactions across Market Contracts. It also handles protocol configurations, user flows, and maintains an overarching governance layer for seamless cross-market operations.
This foundational architecture was further enhanced with built-in compatibility for future trading features, such as leveraged trading and limit orders, ensuring the protocol’s long-term adaptability.
THE DEVELOPMENT PROCESS
The development process was comprehensive and iterative, focusing on ensuring both functionality and security at every stage. The key phases included:
- Research and Planning:
- Conducted an in-depth analysis of existing money market protocols to identify gaps and opportunities for innovation.
- Defined key features and developed a roadmap for implementing a multi-collateral lending/borrowing system with integrated governance.
- Tokenomics Design:
- Created a detailed economic model to incentivize participation by both lenders and borrowers.
- Designed mechanisms for distributing rewards in the form of dTokens, which represent interest-bearing deposits.
- Core Features Implementation:
- Developed user flows for essential operations, including supply, borrow, repay, and withdraw functions.
- Integrated a price oracle to ensure accurate asset valuations for collateral management and interest calculations.
- Built a robust liquidation mechanism and an automated liquidation bot to maintain protocol stability during market fluctuations.
- Security Measures:
- Conducted multiple internal smart contract audits to identify and mitigate vulnerabilities.
- Implemented fail-safes to prevent over-leveraging and ensure asset protection for both lenders and borrowers.
- Testing and Optimization:
- Carried out extensive testing on testnets to validate the protocol’s functionality and performance under various scenarios.
- Optimized gas usage to minimize transaction costs for users.
CHALLENGES WE CONFRONTED
The development process was not without its challenges. Some of the key issues included:
- Cross-Contract Call Management: The distributed nature of NEAR’s ecosystem required meticulous coordination of cross-contract calls and state updates. Ensuring consistent and error-free interactions between Market Contracts and the Controller Contract was a complex and resource-intensive task.
- Scalability Concerns: Balancing the protocol’s scalability with its decentralization posed architectural challenges, particularly in ensuring that the system could handle increasing user demand without compromising efficiency.
RESULTS
The Money Market Protocol milestone resulted in a fully functional borrow/lending platform that set the stage for OMOMO’s growth. The delivered solution:
- Enabled permissionless borrowing and lending, offering users complete control over their financial activities.
- Established a secure, transparent, and decentralized infrastructure for DeFi operations on the NEAR blockchain.
- Provided a robust foundation for subsequent milestones, including trading enhancements and advanced user features.
MILESTONE 2: LIMIT ORDERS IMPLEMENTATION
WHAT WAS THE TASK?
The task for this milestone was to implement decentralized limit orders, a trading feature that allows users to specify the exact price at which they want to buy or sell an asset. Unlike traditional market orders, limit orders provide traders with greater control over their strategies and help mitigate risk. OMOMO’s unique implementation of limit orders required zero swap fees by leveraging Ref.finance’s concentrated liquidity pools. This effort aimed to:
- Enable automated trading strategies based on user-defined parameters.
- Provide a seamless trading experience with no additional costs for swaps.
- Enhance the overall trading efficiency and user control within the OMOMO ecosystem.
PROJECT ARCHITECTURE
The architecture for limit orders was designed to integrate seamlessly with OMOMO’s existing infrastructure while utilizing Ref.finance’s advanced liquidity features. Key components included:
- Smart Contract Integration: OMOMO’s contracts were extended to support limit order functionalities, including order creation, execution, and cancellation.
- Concentrated Liquidity Mechanism: Ref.finance’s concentrated liquidity pools were employed to execute limit orders without incurring swap fees, ensuring cost efficiency for users.
- Order Matching Logic: A robust order matching system was implemented to ensure that user-defined conditions were met before executing trades.
THE DEVELOPMENT PROCESS
Developing the limit orders feature required a focused and agile approach, given the complexity of integrating with external protocols and the tight deadlines imposed by the NEAR IRL Hackathon. The process included:
- Initial Research and Planning:
- Conducted an in-depth analysis of Ref.finance’s API and its capabilities.
- Designed a system architecture that could seamlessly integrate with OMOMO’s existing lending/borrowing functionalities.
- Development and Integration:
- Extended OMOMO’s smart contracts to include limit order creation, tracking, and execution mechanisms.
- Implemented a mechanism to interact with Ref.finance’s liquidity pools for fee-free swaps.
- Developed manual mathematical models to replicate Ref.finance’s pricing and liquidity calculations due to the absence of an SDK at the time.
- Testing and Optimization:
- Performed extensive testing to ensure accurate and reliable execution of limit orders under various scenarios.
- Optimized contract interactions to reduce gas consumption and improve system efficiency.
- Hackathon Delivery:
- Delivered a functional MVP of the limit order system within the constrained timeframe of the hackathon.
- Fine-tuned the system based on initial user feedback and performance metrics.
CHALLENGES WE CONFRONTED
Developing and implementing the limit order functionality presented several unique challenges:
- Lack of SDK Support: Ref.finance’s API was effectively a black box, requiring the team to manually calculate and replicate its internal logic for liquidity management and pricing.
- Tight Deadlines: The NEAR IRL Hackathon imposed a strict timeline, necessitating long hours and rapid iteration to deliver a working MVP.
- System Coordination: Ensuring seamless interactions between OMOMO’s contracts and Ref.finance’s liquidity pools required meticulous testing and validation to prevent errors during order execution.
RESULTS
Despite the challenges, the milestone was successfully completed, delivering significant advancements for OMOMO’s trading ecosystem:
- Zero Swap Fees: Implemented a decentralized limit order system that eliminates swap fees, making trading more cost-effective for users.
- Enhanced User Control: Provided traders with the ability to specify precise execution conditions, improving their ability to manage risk and optimize strategies.
- Hackathon Success: Won the Ref.finance bounty at the NEAR IRL Hackathon, validating the technical excellence and innovation of the implementation.
- Integration with Leverage Trading: The limit order functionality laid the groundwork for the development of OMOMO’s leverage trading system, further enhancing its ecosystem.
MILESTONE 3: LEVERAGE TRADING DEVELOPMENT AND IMPLEMENTATION
WHAT WAS THE TASK?
The objective of this milestone was to implement leverage trading capabilities, enabling users to amplify potential returns by opening larger positions using borrowed funds. This feature required:
- Seamless integration with OMOMO’s existing lending/borrowing protocol.
- Utilization of Ref.finance as the decentralized exchange (DEX) for executing trades.
- Comprehensive risk management mechanisms to protect users and the protocol.
This milestone also included the design and delivery of an MVP for leverage trading to be presented at the METABUILD III Hackathon.
PROJECT ARCHITECTURE
The architecture for leverage trading was designed to align with OMOMO’s modular framework. Key components included:
- Position Management Logic: Designed to handle the lifecycle of a leveraged position, including opening, modifying, and closing positions.
- Risk Mitigation Mechanisms: Implemented through price oracles and liquidation bots to monitor positions and minimize risks during market fluctuations.
- Integration with Ref.finance: Ref.finance’s AMM served as the foundation for executing trades, ensuring deep liquidity and optimal price execution.
- Gas Optimization: Specific optimizations were made to ensure that cross-contract calls remained cost-effective for users, even during complex operations.
THE DEVELOPMENT PROCESS
The development process was structured into several iterative phases to ensure thorough testing and refinement:
- Initial Planning and Design:
- Detailed the requirements for leverage trading, including support for both long and short positions.
- Created a roadmap with clearly defined milestones to prioritize development and testing efforts.
- Implementation of Long Positions:
- Developed functionality to allow users to open and manage long positions by borrowing assets and trading them on Ref.finance.
- Built mechanisms for automated debt repayment and profit calculation upon position closure.
- Short Positions and Take-Profit Orders:
- Extended the logic to support short positions, enabling users to profit from declining asset prices.
- Implemented take-profit orders to allow users to lock in gains when assets reach a specified value.
- Addressed complex flows to ensure that take-profit logic worked seamlessly across all scenarios.
- Testing and Optimization:
- Conducted extensive testing on testnets to validate the system’s behavior under various market conditions.
- Optimized gas consumption across all contract interactions to enhance cost efficiency.
- User Interface Development:
- Designed an intuitive user interface to simplify the process of opening, managing, and closing leveraged positions.
- Integrated real-time analytics and position tracking to enhance the user experience.
CHALLENGES WE CONFRONTED
Several technical and operational challenges were encountered during this milestone:
- High Gas Costs: Implementing leverage trading required multiple cross-contract calls, leading to high gas consumption. Extensive optimization efforts were necessary to reduce costs while maintaining system reliability.
- Position Limits: Ref.finance imposed restrictions on the maximum positions per user, which required additional logic to manage and distribute trading activity effectively.
- Fail-Safe Mechanisms: Building a fail-proof asynchronous system that could handle potential failures or delays in contract interactions posed significant complexity.
- Market Volatility: Addressing the risks associated with sudden price changes required robust risk management strategies and real-time monitoring tools.
RESULTS
The leverage trading functionality was successfully implemented and delivered several key benefits to OMOMO users:
- Comprehensive Trading Features: Enabled both long and short positions with up to 3x leverage, providing users with a powerful tool to amplify their returns.
- Enhanced User Experience: Delivered a polished UI with integrated analytics, allowing users to manage positions seamlessly and track performance in real-time.
- Cost Efficiency: Optimized gas usage across all interactions, ensuring affordability for users engaging in leveraged trades.
- Hackathon Achievement: Successfully presented the MVP at the METABUILD III Hackathon, demonstrating the system’s capabilities and potential.
This milestone established OMOMO as a versatile and robust DeFi platform capable of catering to advanced traders while maintaining a user-friendly approach.
GENERAL RESULTS
The collaboration between Blaize and OMOMO resulted in a comprehensive DeFi platform with:
- A permissionless borrow/lending protocol enabling decentralized financial operations.
- Advanced trading tools like zero-swap-fee limit orders and leveraged trading.
- Increased trading volumes and liquidity utilization within the NEAR ecosystem.
- A user-friendly and efficient platform that sets a benchmark for innovation in decentralized finance.
OMOMO now stands as a testament to Blaize’s expertise in blockchain development, with a seamless blend of technical innovation and user-centric design. The journey continues, with OMOMO positioned as a leader in the NEAR ecosystem’s DeFi landscape.