Inspiration

BlockBorrower is inspired by the vast potential of NFTs on the Ethereum mainnet. More than mere collectibles, I see NFTs as digital assets comparable to gold or real estate. Traditionally, such assets are leveraged for credits on the time of need, reclaimable after repaying the loan, while banks benefit from interest. Why not extend this to a decentralized, peer-to-peer framework?

Hence, I created BlockBorrower. This platform allows you to use your Sepolia chain NFTs as collateral for instant XRP loans. Should you fail to repay, the bank can auction off the NFT. But the beauty of BlockBorrower is its dual role; not only can you borrow, but you can also become a lender. Embrace the role of a financial influencer 🦈 in the DeFi XRP credit system, form lender alliances, and earn profits, all while contributing to the evolution of digital finance. 🏦

What it does

For Customers

  • NFT Transfer Between Chains: Effortlessly transfer your NFTs between the Sepolia chain and XRP EVM Compatible chain. Our Locker, Minter, and Relayer system ensures a seamless and secure cross-chain transfer experience πŸ”„.

  • Instant XRP Credit: Pledge your NFTs and receive immediate XRP credits based on the NFT's value and specific bank rules. Enjoy the stability of fixed interest rates for a hassle-free borrowing experience πŸ’°.

  • Flexible Repayment: Benefit from a fair EMI system coupled with simple interest, providing you with a stress-free repayment plan tailored to your financial capabilities πŸ“Š.

  • NFT Retrieval: Regain possession of your NFTs after complete loan repayment, ensuring your digital assets remain yours following the fulfillment of financial obligations πŸ–ΌοΈ.

  • Auction Claim: Receive a refund for any amount already paid towards the loan if your NFT is auctioned, maintaining fairness even in auction scenarios πŸ”¨.

  • Fair Auction Rules: Experience equitable auction processes, defined by preset default limits and a grace period after the loan term, ensuring a balanced approach to asset liquidation βš–οΈ.

  • Auction Participation: Engage in bidding for NFTs at auction; secure ownership if you emerge as the highest bidder, adding an exciting NFT to your collections. 🎯.

  • Bid Refund: Retrieve your bid amount if not successful at an auction, ensuring a risk-free participation process in the bidding environment πŸ”„.

  • Bank Exploration: Explore various banks within the platform before deciding on your loan provider, allowing for informed financial decisions based on diverse terms and offerings πŸ”.

  • Loan Management: Utilize a personalized dashboard for comprehensive loan management, simplifying the oversight of your financial commitments and repayment progress πŸ“ˆ.

For Lenders

  • Bank Creation: Establish your own bank with sufficient capital, or join an existing institution, stepping into the influential role of a lender within the DeFi space πŸ’Ό.

  • Flexible Participation: Join a bank as a lender regardless of your fund size, democratizing the lending landscape and offering opportunities for various investment capacities πŸ’Έ.

  • Bank Browsing: Survey a range of banks prior to joining, aligning yourself with an institution that resonates with your investment ethos and expectations πŸ•΅οΈβ€β™‚οΈ.

  • Funds Management: Efficiently manage your banking capital with straightforward deposit and withdrawal functionalities, ensuring fluidity in your financial transactions πŸ’Ή.

  • Interest and Tenure Control: As a bank admin, tailor the lending terms by setting bespoke interest rates and loan durations, customizing your banking operations to suit your strategic goals πŸ› οΈ.

  • Freedom to Exit: Exercise the right to disengage from a bank if it fails to meet your criteria or expectations, maintaining autonomy in your lending journey πŸšͺ.

  • Bank Closure Guidelines: Close your banking operations responsibly, adhering to smart contract standards that prevent closure during active loans or the presence of lenders in the bank 🏦.

  • Loan Oversight: Administer and calculate dues for issued loans with precision, ensuring effective management and financial accountability of your lending activities πŸ”.

  • Detailed Loan Tracking: Monitor each loan in your portfolio in detail, staying informed and proactive in managing your financial engagements πŸ“‹.

  • Auction Authority: Initiate auctions for loans in default, guided by predetermined benchmarks, balancing control in loan recovery with fairness in borrower treatment πŸ”¨.

  • Asset Valuation: Strategically set and lock in the haircut value for assets in your bank, prompting thoughtful valuation that remains consistent throughout your banking operations πŸ“‰.

  • Fair Profit Sharing: Implements an equitable profit and loss apportionment model among lenders, fostering a collaborative and just environment that mitigates potential disputes and ensures fair earnings distribution πŸ‘₯.

  • Auction Management: Oversee the auction process with flexibility to start, finalize, or cancel based on situational assessment, adapting to the dynamic financial landscape πŸŽ›οΈ.

  • Loan Status Checks: Conveniently verify the closure status of loans at any time, ensuring transparency and up-to-date information on your lending portfolio πŸ“Š.

Customer Lifecycle

  • Transfer your NFTs in Sepolia Chain to EVM XRPL Chain using the SX Relayer
  • Take a Loan against your NFT
  • Repay your loan
  • Withdraw your NFT and transfer it back to Sepolia chain using the SX Relayer

Smart Contract Governance Rules

  • Minimum Capital for Bank Creation: To establish a bank within the platform, a minimum capital of 450 XRP is required, ensuring that each bank starts with a substantial base for lending operations 🏦.

  • Minimum Investment to Join a Bank: An individual can join an existing bank with a minimum investment of 200 XRP, making the platform accessible to a wide range of participants 🀝.

  • Fixed Late Payment Fee: A flat late payment fee of 1 XRP is charged, regardless of the delay duration from the due date, simplifying the penalty structure for late repayments πŸ’Έ.

  • Deposit Threshold: The minimum deposit amount to a bank is set at 1 XRP. πŸ’°.

  • Claiming Loan Balances: When claiming the balance of a loan from a bank, the minimum amount must exceed 1 XRP, ensuring meaningful transaction sizes and financial efficiency πŸ”„.

  • Monthly Repayment Structure: Loans are repaid on a monthly basis (EMI), offering a structured and predictable repayment schedule for borrowers πŸ“†.

  • Immutable Defaulting and Grace Periods: Once set, bank admins cannot alter the defaulting period and grace period, ensuring consistency and fairness in loan terms βŒ›.

  • Restrictions on Bank Closure: Bank admins are prohibited from closing a bank if there is an active loan or an active lender, maintaining a stable and reliable lending environment 🚫.

  • Auction Duration for NFTs: NFTs are auctioned for a standard duration of 7 days. For testing purposes, this is adjusted to 20 minutes, allowing for expedited simulation and evaluation ⏳.

  • Minimum Bid Amount: The minimum amount required to place a bid in an auction is set at 1 XRP, encouraging broad participation while maintaining value in the bidding process πŸ”¨.

  • Proportional Profit or Loss Sharing: Profits or losses are shared among participants based on proportionality, ensuring a fair and equitable distribution aligned with each participant's stake in the bank πŸ’Ή.

How we built it

Architecture for Sepolia to EVM XRP Sidechain and EVM XRP Sidechain to Sepolia NFT transfer mechanism

Architecture image

Sepolia to EVM XRP Sidechain NFT Transfer

  • Transaction Initiation: Users initiate the transfer by sending a transaction indicating their desire to transfer a specific NFT (identified by its ID and contract address) to the EVM XRPL chain πŸ”„.

  • NFT Locking: The NFT is locked inside a 'locker' contract, transferring its ownership to the locker. This NFT is then mapped to the user's address πŸ”’.

  • Lock Event and Minting: Upon the emission of a 'lock' event, a relayer sends a mint message to the EVM XRPL Minter smart contract, which then mints a corresponding NFT 🌐.

  • Minting Failure Fallback: In case minting fails, the relayer triggers a fallback unlocking in the locker contract, allowing the user to withdraw the NFT if needed 🚨.

  • Successful Transfer Confirmation: If minting is successful, the Minter emits a 'MINTED' event. The relayer then informs the locker to finalize locking, transitioning from 'LOCK_INITIATED' to 'LOCKED' state βœ….

  • IBCNFT Token Receipt: The user receives an IBCNFT token on the other chain as a substitute for the NFT sent from Sepolia, ideally maintaining the same value πŸ’±. The token name is Inspired by the name IBC protocol of cosmos, and does not follow ICS-721 standard.

From EVM XRP Sidechain to Sepolia NFT Transfer

  • Transaction Initiation: Users initiate the transfer back by sending a transaction indicating their intent to return the NFT πŸ”„.

  • Token Ownership Transfer: Ownership of the token is transferred to the Minter πŸ”„.

  • Burn Initiation: The Minter emits a 'BURN_INITIATED' event πŸ”₯.

  • Unlocking Mechanism: This event is captured by the relayer, which then initiates an 'UNLOCK' function in the locker contract, unlocking the NFT and emitting an 'UNLOCK' event πŸ”“.

  • Failed Transaction Handling: If the transaction fails, the burn process is reverted, and the NFT's ownership is transferred back to the user who initiated the transfer 🚨.

  • Successful Burn and Finalization: On successful transaction completion, the relayer instructs the Minter contract to permanently burn the IBCNFT token πŸ”₯.

  • NFT Withdrawal by Recipient: The intended recipient can now withdraw the NFT from the locker contract βœ….

The entire process is facilitated through a bridge UI, which I call the SX-Relayer, integrated with the Blockborrower portal, enabling ease of use with both native EVM XRPL and Sepolia NFTs πŸŒ‰.

BlockBorrower Contract to Auction Smart contract Interaction

BlockBorrower contract is designed to effectively interact with the auction contract through precise data exchange. BlockBorrower initiates commands like 'start auction,' 'finalize auction,' and 'cancel auction' to the auction smart contract using a composition-based design approach. Upon receiving the necessary return values from the auction contract, BlockBorrower updates the relevant loan data associated with the bank accordingly. However, the 'place a bid' function is distinct and can be directly invoked from the auction smart contract. Once an auction is initiated by the contract, it becomes immutable for others except the blockborrower contract; modifications are not permissible from the auction contract side. Any changes require a transaction to be sent from the BlockBorrower smart contract.

Image for blockborrower to auction contract interaction

Credit and Debit Apportionment

In the BlockBorrower platform, a bank's credit or debit is distributed among lenders based on their proportional contribution to the total bank balance. Let's illustrate this with a bank comprising N lenders, each holding a different balance. For example:

  • Lender 1: 200 XRP
  • Lender 2: 300 XRP
  • Lender 3: 500 XRP

The total balance of the bank is 1000 XRP.

Suppose the bank earns a credit of 200 XRP. The Credit is distributed in proportion to each lender's share in the total bank balance. The formula used is:

Lender's Share = (Lender's Balance X credit) / Total Bank Balance

Applying this formula, we get:

  • Lender 1's Share: (200 X 200)/1000 = 40 XRP
  • Lender 2's Share: (300 X 200)/1000 = 60 XRP
  • Lender 3's Share: (500 X 200)/1000 = 100 XRP

After distributing the profit, their final balances are:

  • Lender 1: 240 XRP
  • Lender 2: 360 XRP
  • Lender 3: 600 XRP

In case of debit the final balance of lenders will be

  • Lender 1: 160 XRP
  • Lender 2: 240 XRP
  • Lender 3: 400 XRP

If the division results in odd amounts, Solidity rounds up the figures. Any excess amount from this rounding is added to or subtracted from the bank admin’s balance, acknowledging their role and initiative.

As a result, the bank's total balance post-credit distribution increases to 1200 XRP or decreases to 800 XRP post-debit. This approach ensures a fair and equitable distribution of credits/debits, aligning with each lender's investment in the bank.

Technologies I Used

  • Vue JS: Utilized for crafting a dynamic and reactive front-end interface.
  • Web3 JS: For seamless interaction with Ethereum smart contracts.
  • Solidity: Programming language used for writing ethereum smart contracts.
  • Alchemy: Provides access to Ethereum's RPC URL and WSS URL for effective event listening.
  • XRP EVM Sidechain Documentation: Resource for understanding the integration and functionality of XRP's EVM sidechain.
  • XRP EVM Bridge: A bridge mechanism enabling transactions between XRP and its EVM sidechain.
  • Golang: Used for developing the relayer, ensuring efficient and reliable data transmission.
  • Bash: Scripting language used for creating and maintaining the relayer service, including auto-restart features.
  • Linode: Cloud hosting service used for deploying and managing the relayer.
  • REMIX IDE: Interactive development environment for creating and testing Ethereum smart contracts.
  • Metamask and XUMM Wallet: Tools for exploring and understanding interactions between the XRPL and EVM sidechain.

Challenges we ran into

  • Fair Apportionment Logic Development: To ensure equitable distribution, I adopted a simple proportionality-based approach. This required careful consideration to maintain fairness in resource allocation.

  • Optimizing Data Handling Methods: After conducting a Big O complexity analysis, I decided between using a list or double mappings for data management. The double mapping approach proved more efficient for our specific use-case.

  • Defining Transaction Conditions: Initially, the interdependencies of transactions (e.g., auction-related functions within the repayEMI function) were unclear. To address this, I employed an iterative development model, allowing for gradual refinement and integration of transaction conditions.

  • Parameter Selection for Simulated Banking System: A significant challenge was choosing the most representative parameters for a banking system within our Solidity smart contract, ensuring both simplicity and functionality.

  • Resolving Apportionment Logic Errors in Claim Balances: During the QA cycle, we identified a flaw where missed apportionment logic led to potential double expenditure. This required immediate rectification to maintain system integrity.

  • Building a Reactive Front-End with Alchemy Web3: Using Alchemy Web3 with Vue presented challenges, especially as it required a specific version of Vue to function optimally.

  • Node Update and Polyfill-Tools Issue: Updating the node resulted in a complication where polyfill-tools, essential for the Alchemy Web3 package, were not imported automatically. This required a manual editing in vue.config.js.

  • Event Listening on the EVM XRP Sidechain: The EVM XRP sidechain's lack of notification support posed a challenge in event listening. I overcame this by implementing a polling mechanism and using LevelDB to uniquely identify logs through the hash of blockNumber, blockHash, and logIndex.

  • Linking Auction and Blockborrower Contracts: Ensuring data consistency between the auction contract and the blockborrower contract was crucial. This required careful integration to maintain coherence and accuracy.

  • Relayer Accessibility and Trust Issues: The challenge was to make the relayer accessible to all users while preventing inconsistencies in multiple transactions. Initially, it operated on an ownership model where only the contract deployer could relay messages. However, to align with decentralized principles, this approach needed reevaluation to reduce reliance on trust.

Accomplishments that we're proud of

  • Golang-Based Relayer Implementation: Successfully used Golang to develop a relayer that efficiently reads notifications from both the Sepolia chain and the EVM-XRPL chain, utilizing subscriber and polling methods respectively.

  • Relayer Stabilization via Bash Script: Crafted a Bash script that intelligently restarts the relayer if it encounters an EOF error, enhancing the system's stability and reliability.

  • Cross-Chain Transfer Achievement: Successfully implemented cross-chain transfer functionality, following ICS-721 standard to some extent but not entirely.

  • Development of a Near-Production Ready DeFi Application: Developed a comprehensive DeFi application, which stands close to being production-ready in terms of functionality and (security needs to be reconsidered).

  • Visually Aesthetic Front-End Creation: Designed a visually appealing and user-friendly front-end interface, enhancing user experience and engagement.

  • Smart Contract Interactions via Web3 JS: Effectively utilized Web3 JS for interacting with smart contracts.

  • Full-Fledged DApp Using XRP Currency: Developed a comprehensive decentralized application (DApp) that incorporates XRP currency.

  • Governance Rules Definition for Smart Contracts: Successfully established and defined governance rules for smart contracts, ensuring orderly and secure operations.

  • Advanced Use of Vue JS: Implemented complex features in Vue JS, including modal popups and dashboard views.

  • EVM XRP Sidechain Compatible Application: Created a specialized application compatible with the EVM XRP sidechain, focusing on the use of XRP as the principal currency.

What we learned

  • Development of a Comprehensive DApp: Gained expertise in building a full-fledged Decentralized Application (DApp) using Solidity, Web3 JS, and Vue JS, integrating blockchain with front-end technologies.

  • Golang Relayer Creation: Learned to create a Golang-based relayer for listening to smart contract events, focusing on the use of subscribers for real-time data handling.

  • Polling Mechanisms for Event Listening: Understood the concept of polling and its application in event listening, providing a robust alternative to traditional event handling methods.

  • Identification of Unique Logs: Learned to determine the uniqueness of logs, an essential aspect of data integrity and security in blockchain applications.

  • Exploration of ICS-721 Standard: Gained insights into the ICS-721 standard for cross-chain asset transfers, understanding its applications and tried to implement it as much as possible in context of our project.

  • Utilization of XRP in Development: Explored the use of XRP currency, recognizing its potential as a future-leading digital currency and integrating it into our development process.

  • Hashing and Round Up Logic in Solidity: Enhanced understanding of hashing techniques and round-up logic in Solidity, crucial for data security and efficiency.

  • Block Time Calculation Techniques: Learned to calculate block time using Web3 and Go-Ethereum, a vital skill for understanding and optimizing blockchain operations.

  • Proficiency with Go-Ethereum Library: Acquired knowledge in using the Go-Ethereum library, expanding technical capabilities in blockchain development.

  • Bash Scripting for Deployment Stability: Developed proficiency in Bash scripting to ensure the stability and reliability of deployments, improving overall system resilience.

What is next for Block-Borrower

  • Building a Distributed Relayer: Aim to develop a relayer that is both distributed and decentralized, ensuring data consistency and preventing multiple transactions. This involves integrating a common decentralized database to achieve full decentralization.

  • Full Incorporation of ICS-721: Plan to integrate all aspects of the ICS-721 standard in the asset transfer process from the Sepolia chain to the XRP EVM compatible sidechain and vice versa, enhancing cross-chain interoperability.

  • Complex Repayment System: Enhance the repayment system to include more intricate features like late payment interest charges and grace periods, making it more robust and realistic.

  • Expansion of Banking and Loan Management Parameters: Focus on identifying and integrating additional parameters for bank and loan management to improve functionality and user experience.

  • Loan and Lending System Modularization: Work on segregating loan management and lending systems into multiple interacting contracts, promoting modularity and scalability.

  • Smart Contract as a Credit Bureau: Create a smart contract system that acts as a credit bureau for blockborrower contract evaluating credit scores for customer based on their previous credit history. Also it will incorporate an oracle services to fetch centralized bureau data and integrate both of these scores using a fair mathematical formula.

  • Complex and Configurable Governance System: Develop a more intricate and configurable governance system for smart contracts to enhance control and flexibility.

  • Advanced Apportionment Logic: Aim to create more complex apportionment logic for improved resource allocation and distribution.

  • Enhanced Repayment Schedules: Plan to broaden the repayment schedule options to include partial and full payments, offering more flexibility to users.

  • Optimizing Solidity Functions for Gas Efficiency: Focus on increasing the efficiency of Solidity functions to reduce gas costs, enhancing overall performance and cost-effectiveness.

  • Front-End Enhancement: Improve the front-end design to make it more aesthetically pleasing and production-ready, enhancing user experience and interface appeal.

  • Implementing compound interest: Making the selection of interest type configurable, and implementing the choice of having simple or compound interest.

Built With

Share this project:

Updates