Conversation
| @@ -0,0 +1,4 @@ | |||
| import "./endpoints/lending"; | |||
| import "./endpoints/wallet"; | |||
There was a problem hiding this comment.
why liquidityPools endpoints not imported?
| @@ -0,0 +1,76 @@ | |||
| # Lending Protocol on CCF Framework | |||
There was a problem hiding this comment.
An explanation how to use it would be great as it would make the whole example standalone.
| - **Withdraw Token**: `/wallet/withdraw` | ||
| - **Get Wallet Balance**: `/wallet/balance` | ||
|
|
||
| ### Lending Endpoints |
There was a problem hiding this comment.
Are these endpoints correct? lending.ts has only 2 methods exported
There was a problem hiding this comment.
will update the lending.ts as i forgot to add endpt to remove collateral and remove liquidity
| @@ -0,0 +1,9 @@ | |||
| { | |||
There was a problem hiding this comment.
scripts section is missing, I would expect some basic ones such as build or test
There was a problem hiding this comment.
let me add the build script to generate app.json
|
I could not start it as there is a missing config it seems: # start the ccf sandbox container ...
docker run --rm -it --entrypoint=/bin/bash -v `pwd`:/app ghcr.io/microsoft/ccf/app/dev/virtual:ccf-5.0.0
# install nodejs
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt-get install -y nodejs
# build the app
cd /app/lending-app
npm i
npx tsc
# run the app
/opt/ccf_virtual/bin/sandbox.sh --js-app-bundle ./dist/ends up with the error: |
will fix thanks for catching it |
Title: Implement Lending Protocol with Collateralized Borrowing and Liquidity Management
Overview
This PR introduces the core functionality for a decentralized lending protocol, including:
Collateralized Lending:
Users can deposit BTC and ETH as collateral to borrow USDT.
Borrowing limits are enforced using a configurable collateral factor.
Liquidity Pool Management:
Separate liquidity pools for BTC and ETH.
Users can add or remove liquidity, and interest rewards are distributed as DEFI tokens.
Wallet Management:
Users can deposit, withdraw, and query their wallet balances for supported tokens (BTC, ETH, USDT, and DEFI).
Interest Accrual:
Liquidity providers earn DEFI tokens as interest, distributed proportionally based on their contribution to the pools.
Major Changes
Endpoints:
depositTokenEndpoint: Deposit tokens into the user's wallet.
withdrawTokenEndpoint: Withdraw tokens from the user's wallet.
getWalletBalanceEndpoint: Retrieve wallet balance for a specific token.
addCollateralEndpoint: Deposit tokens as collateral.
borrowEndpoint: Borrow USDT tokens against collateral.
removeLiquidityEndpoint: Withdraw liquidity from BTC or ETH pools.
Modules:
Wallet Module:
depositToken: Adds tokens to a user's wallet.
withdrawToken: Deducts tokens from a user's wallet.
Lending Module:
addCollateral: Manages collateral deposits for borrowing.
borrow: Validates collateral, withdraws tokens from liquidity, and credits them to the user's wallet.
removeLiquidity: Allows users to withdraw their liquidity from the pool.
Liquidity Pools:
Added poolTable to manage BTC and ETH pools.
Tracks totalLiquidity and user contributions for each token.
Workflow Examples
Adding Liquidity:
User deposits 2 BTC into the BTC pool using addLiquidity.
The pool's total liquidity increases, and the user's contribution is tracked.
Borrowing Tokens:
User with sufficient BTC collateral borrows 1000 USDT.
Tokens are deducted from the USDT pool and credited to the user's wallet.
Interest Accrual:
Liquidity providers in BTC and ETH pools earn DEFI tokens proportional to their contributions.
Wallet Operations:
Users can deposit, withdraw, or query their wallet balances for supported tokens.
Configuration
Collateral Factor: Configurable via COLLATERAL_FACTOR (default: 1.5).
Base Interest Rate: Configurable via BASE_RATE (default: 2% per period).
Key Features
DeFi Standards:
Aligns with real-world DeFi protocols like Aave, enabling collateralized borrowing and interest distribution.
Scalable Design:
Modular structure with separate modules for wallet, lending, and liquidity pool management.
Security and Validation:
Comprehensive input validation and error handling in all endpoints.