Cross-Chain Lending Protocol Submission
Project Overview
A decentralized cross-chain lending protocol enabling users to request loans on Ethereum Sepolia with ETH collateral and receive/repay loans in MATIC on KOPLI, utilizing Reactive Network for secure cross-chain communication.
Cross-Chain Lending dApp Flow
1. User Onboarding
- User visits the dApp website
- Connects their wallet (e.g., MetaMask) to the dApp
- The dApp detects the connected network (Ethereum Sepolia or KOPLI)
2. Borrowing Process
A. Collateral Deposit (on Ethereum Sepolia)
- User navigates to the "Borrow" tab
- Enters the amount of ETH they want to use as collateral
- The dApp calculates and displays:
- Collateral value in USD (using Chainlink ETH/USD price feed)
- Maximum loan amount in MATIC
- Estimated interest rate
- Loan-to-Value (LTV) ratio
- Liquidation threshold
- User selects loan duration and confirms the transaction
- The
OriginContract
on Ethereum Sepolia is called:depositCollateral()
function is executed- Collateral is locked in the contract
- Loan details are stored in the contract
CollateralDeposited
andLoanInitiated
events are emitted
B. Loan Issuance (on KOPLI)
- The Reactive Contract (off-chain) listens for the
LoanInitiated
event - It triggers a cross-chain message to the KOPLI network
- The
DestinationContract
on KOPLI receives the message and:- Calls the
fundLoan()
function - Transfers MATIC to the user's wallet
- Emits a
LoanIssued
event
- Calls the
- The dApp frontend updates to show the loan has been issued
3. Loan Management
A. Monitoring
- The dApp regularly updates the loan status, including:
- Current collateral value
- Amount owed (principal + interest)
- Time until due date
- Current LTV ratio
- If the LTV ratio approaches the liquidation threshold, the dApp alerts the user
B. Repayment (on KOPLI)
- User navigates to the "Repay" tab
- Selects the loan they want to repay
- Enters the repayment amount in MATIC
- Confirms the transaction
- The
DestinationContract
on KOPLI:- Calls the
repayLoan()
function - Updates the loan status
- Emits a
LoanRepaid
event
- Calls the
- If the loan is fully repaid:
- Emits a
LoanFullyRepaid
event - The Reactive Contract sends a cross-chain message to Ethereum Sepolia
- Emits a
C. Collateral Release (on Ethereum Sepolia)
- The
OriginContract
receives the cross-chain message about full repayment - It calls the
releaseCollateral()
function:- Transfers the locked ETH back to the user
- Emits a
CollateralReleased
event
- The dApp frontend updates to show the collateral has been released
4. Liquidation Process
A. Liquidation Trigger
- The dApp or an off-chain bot monitors the LTV ratios of all loans
- If a loan's LTV ratio exceeds the liquidation threshold:
- The bot or a liquidator calls the
liquidateLoan()
function on theDestinationContract
- The bot or a liquidator calls the
B. Liquidation Execution
- On KOPLI:
- The
DestinationContract
verifies the liquidation conditions - Marks the loan as liquidated
- Emits a
LoanLiquidated
event
- The
- The Reactive Contract sends a cross-chain message to Ethereum Sepolia
- On Ethereum Sepolia:
- The
OriginContract
receives the liquidation message - Calls the
liquidateLoan()
function - Transfers the collateral to the contract owner or designated insurance fund
- Emits a
LoanLiquidated
event
- The
Architecture Components
1. Origin Chain (Ethereum Sepolia)
- Contract:
OriginContract
- Functions:
requestLoan(uint256 _loanAmount, address _destinationChain)
depositCollateral()
releaseCollateral(address _user)
liquidateLoan(address _user)
2. Reactive Network Bridge
- Contract:
ReactiveContract
- Cross-chain Event Handlers:
- LoanRequested handler
- LoanInitiated handler
- LoanFullyRepaid handler
- LoanLiquidated handler
3. Destination Chain (KOPLI)
- Contract:
DestinationContract
- Functions:
requestLoan(address _borrower, uint256 _amount, uint256 _interestRate, uint256 _durationInDays, uint256 _creditScore)
fundLoan(address _borrower)
repayLoan()
liquidateLoan(address _borrower)
Contract Events
OriginContract Events
event LoanRequested(address indexed user, uint256 loanAmount, address destinationChain);
event CollateralDeposited(address indexed user, uint256 amount, address destinationChain, uint256 loanAmount);
event LoanInitiated(address indexed user, uint256 loanAmount, address destinationChain, uint256 interestRate);
event CollateralReleased(address indexed user, uint256 amount);
event LoanLiquidated(address indexed user, uint256 collateralAmount, uint256 loanAmount);
DestinationContract Events
event LoanRequested(address indexed borrower, uint256 amount, uint256 interestRate);
event LoanFunded(address indexed borrower, uint256 amount);
event LoanRepaid(address indexed borrower, uint256 amount);
event LoanFullyRepaid(address indexed borrower);
event LoanLiquidated(address indexed borrower, uint256 amount);
Deployed Contract Addresses
- Sepolia OriginContract: 0x590BEff93aF028D343Fd03e958d51C123f9aB7b6
- Reactive Bridge Contract Org To Des: 0x55033f19F97b1c8d1dCA347Da2f5F5b955F4B828
- Reactive Bridge Contract Des To Des: 0xd373C76D0922857E27556eFDAD4b39C475561C20
- KOPLI MaticContract: 0x8ef4bc4EC0e3C29Ac484b1B015fd9B570133cdb6
- KOPLI DestinationContract: 0xF32c2c1cc9686D635f5D99ADb07E97a17877F134
Example Transaction Flow
- Loan Request (Sepolia): 0x4d2d94e6bb0349bde7796523fcafdda6fda321cec578708c33816b6607ecf2f4
- Reactive Bridge Transaction OTD: 0x276b15...cf32e7a7
- Collateral Deposit (Sepolia): 0x7d6e40b7c144e63d09be250859874d9bff1d6e19ff3ea51ed86b8d61bc8f782c
- Reactive Bridge Transaction OTD: 0xcc39c3...03c70a60
- Repay Loan (KOPLI): 0xa1b6181da7e2a9e89785a0290a84f498b6ab063689a9e9880255dfc726426f7b
- Reactive Bridge Transaction DTO: 0x776ce8...1ff461c4
Security Features
- Collateral validation checks
- Cross-chain message verification
- Interest rate oracle integration
- Liquidation threshold monitoring
- Emergency pause functionality
- Access control for admin functions