BalloonBox-Inc / near-oracle-algorithm

NearOracle Python backend - Credit scoring algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Near

Credit Scoring on NEAR Protocol ๐Ÿ”ฎ ๐Ÿช ๐Ÿ”

NearOracle is an oracle for credit scoring that runs on the NEAR protocol and serves web3 users interested in lending or borrowing money in the crypto space. This repo contains the Python codebase of the credit scoring algorithm used by the NearOracle dApp, a dApp that BalloonBox developed through a grant by the NEAR Foundation. The oracle reads in the user's fiat or crypto financial history and uses it to calculate a numerical score, namely an integer representing a user's financial health. Ranking users through a credit score is essential to distinguish between trusted and suspicious agents in the web3 space. The dApp caters to a specific use case, namely unsecured P2P lending: facilitating lending and borrowing of crypto loans.

How does the dApp work?
  • it acquires user's financial data by integrating with three validators (Plaid, Coinbase, and MetaMask)
  • it runs the credit scoring algorithm to compute a score assessing a user's financial health
  • it writes the score to the blockchain via a Wasm smart contract built using the Rust NEAR SDK
In this Repo

This GitHub repo contains the codebase of the NearOracle credit score algorithm. The code features 3 validators, 4 API integrations, 12 score metrics, and 25+ functions to calculate users' credit scores. The front end of the NearOracle dApp (see codebase at near-oracle-client), after fetching the user's data and passing it to the algorithm, it executes and returns a score via a Rust smart contract (see codebase at near-oracle-contract).

Continue to read these docs to understand the algorithm or clone this project and spin it up locally.


๐Ÿ™ Directory Structure

The tree diagram below describes the structure of this Git Repo. Notice that the decision tree only features the most important files and disregards all others.

.
โ””โ”€โ”€โ”€
    โ”œโ”€โ”€ config
    โ”‚   โ””โ”€โ”€ config.json               # contains all model parameters and weights - tune this file to alter the model
    โ”œโ”€โ”€ helpers
    โ”‚   โ”œโ”€โ”€ feedback.py               # string formatter returning a qualitative score feedback
    โ”‚   โ”œโ”€โ”€ helper.py                 # helper functions for data cleaning
    โ”‚   โ”œโ”€โ”€ metrics_coinbase.py       # logic to analyze a user's Coinbase account data
    โ”‚   โ”œโ”€โ”€ metrics_covalent.py       # logic to analyze a user's ETH wallet data (powered by Covalent)
    โ”‚   โ”œโ”€โ”€ metrics_plaid.py          # logic to analyze a user's bank account data (powered by Plaid)
    โ”‚   โ”œโ”€โ”€ models.py                 # aggregate granular credit score logic into 4 metrics
    โ”‚   โ”œโ”€โ”€ risk.py                   # high/med/low risk indicators
    โ”‚   โ”œโ”€โ”€ score.py                  # aggregate score metrics into an actual credit score
    โ”‚   โ””โ”€โ”€ README.md                 # docs on credit score model & guideline to clone project
    โ”œโ”€โ”€ market
    โ”‚   โ””โ”€โ”€ coinmarketcap.py          # hit a few endpoints on Coinmarketcap (live exchange rate & top cryptos)
    โ”œโ”€โ”€ routers
    โ”‚   โ”œโ”€โ”€ coinbase.py               # core execution logic - Coinbase
    โ”‚   โ”œโ”€โ”€ covalent.py               # core execution logic - Covalent
    โ”‚   โ”œโ”€โ”€ kyc.py                    # core execution logic - KYC template
    โ”‚   โ”œโ”€โ”€ plaid.py                  # core execution logic - Plaid
    โ”‚   โ””โ”€โ”€ README.md                 # docs on the API endpoints
    โ”œโ”€โ”€ support
    โ”‚   โ”œโ”€โ”€ assessment.py             # tracking memory allocation in database
    โ”‚   โ”œโ”€โ”€ crud.py                   # Create, Read, Update, Delete (CRUD) - database handler
    โ”‚   โ”œโ”€โ”€ database.py               # set up PostgreSQL database to store computed scores
    โ”‚   โ”œโ”€โ”€ models.py                 # clases with data to enter in new row of database
    โ”‚   โ””โ”€โ”€ schemas.py                # http request classes
    โ”œโ”€โ”€ tests
    โ”‚   โ”œโ”€โ”€ coinbase                  # directory with 2 files: Coinbase pytests & dummy test data json
    โ”‚   โ”œโ”€โ”€ covalent                  # directory with 2 files: Covalent pytests & dummy test data json
    โ”‚   โ””โ”€โ”€ plaid                     # directory with 2 files: Plaid pytests & dummy test data json
    โ”œโ”€โ”€ validator
    โ”‚   โ”œโ”€โ”€ coinbase.py               # functions calling Coinbase API
    โ”‚   โ”œโ”€โ”€ covalent.py               # functions calling Covalent API
    โ”‚   โ””โ”€โ”€ plaid.py                  # functions calling Plaid API
    โ”œโ”€โ”€ LICENCE
    โ”œโ”€โ”€ main.py                       # core file - handle API calls, directing them to the router folder
    โ”œโ”€โ”€ Procfile                      # set up uvicorn app in Heroku
    โ”œโ”€โ”€ pytest.ini                    # pytest initializer
    โ”œโ”€โ”€ README.md                     # this landing page
    โ””โ”€โ”€ requirements.txt              # Python modules required to run this project

About

NearOracle Python backend - Credit scoring algorithm

License:Apache License 2.0


Languages

Language:Python 100.0%Language:Procfile 0.0%