Skip to content

zkJoey/joey-mono

Repository files navigation

Welcome to Joey Finance!

zkjoey

👀 Problem

  • Currently, it's difficult for web3 companies/entities to receive funding and loans for growth against the on-chain (and off-chain) revenue. For the space to grow, funding is vital. Unfortunately, traditional financial institutions do not have the know-how to serve them.
    • Types of customers
      • content creators in Web3
      • Web3 companies selling to Web2/3
      • Gaming firms
      • Consumer
      • Science
      • B2B
  • Today, each wallet functions as a debit card. We envision a credit line for every wallet so people can borrow or spend as needed, similar to a credit card in real life.
    • a business could have a revolving credit facility based on the on and off-chain revenue underwriting
    • individuals could have an on-chain credit card (wallet) with a limit linked and signalled against their off-chain credit score, for example

Project Description

Today, each wallet functions as a debit card. We envision a credit line for every wallet so people can borrow or spend as needed, similar to a credit card in real life.

Credit Wallet built using multi-sig Account Abstraction on ZKSync

Businesses or individuals can have credit facilities underwritten by on- and off-chain signals utilizing Huma Protocol

  • data sources - Circle Business Account, Stripe, Request

  • credit scoring - Spectral, Flock

Users can make payments to the vendors and sellers directly from the Huma Pool via ZKBob to keep vendor details private.

In case of late or default on repayments of the credit, the protocol takes ownership of the revenue-receiving contracts.

Stack

  • Dapp (React) using Web3Modal
  • Multisig Account Abstraction for the credit wallet, with second sig for a potential guarantor to co-sign on the credit line
  • Deployed on ZKSync
  • Signal Adapter (python app) for Huma to get data from:
    • Circle Business Account
    • Stripe
    • credit score from Spectral and Flock
    • Request.finance invoices as collateral
  • Evaluation Agent (python app) to consume signals and underwrite credit
  • ZKBob for transfers (direct deposits) from Pool to the end-user (https://docs.zkbob.com/resources/hackathons/zkbob-direct-deposits)
  • In case of default, the pool takes ownership of contracts receiving revenue
  • Dapp built using React
    • login with Web3Modal
    • connect Stripe and Circle keys to feed Signal Adapter
    • Calculate credit limit by Evaluation Agent

Designs

https://www.figma.com/file/xcRfMLTCYX1VMqynL2JeyK/Joey-Finance?node-id=0%3A1&t=mbUVKwGjPf2xoa4L-1

Flows

flows

Bounties

ETHDenver DeFi Track

Huma: A credit line for every wallet

Huma: Launch a real-world lending use case on Huma

Huma: new signal adapters

WalletConnect Web3Modal DeFi Challenge: Making Bank

ZKSync Wallet Logic! (using account abstraction)

Circle:

ZkBob

Spectral

Deployment instructions

Run commands

  • Smart contracts (huma protocol contracts modified for our use)
  • Signal Adapters
  • Evaluation Agent
  • Dapp (TBC)

ETHEREUM

Mono Repo

Smart contracts

### clone mono repo
gh repo clone credit-wallet/joey-mono

### smart contracts
cd smart-contracts
yarn install
yarn build
yarn test
yarn chain

### with yarn chain, the console will print out 20 testing accounts
### Account 6 has sufficient test usdc as a lender
### Account 7 and later can be used as borrowers

### start a new terminal
yarn deploy

### all deployed contract addresses can be found in deployment/localhost-deployed-contracts.json
### If some error happens and you need to start over, run: yarn clear, then deploy again

Signal Adapters

# Signal Adapters API server
cd joey-mono/signal-adapters

# update dotenv file from a copy of example.env
huma_signals/dotenv/development.env

# install poetry
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
poetry install

# run the server
make run-local

Evaluation Agent

# Start the EvaluationAgent service: 
cd joey-mono/evaluation-agent
pip install git+https://github.com/zksync-sdk/zksync-python.git
pip3 install -r requirements.txt
pip install zksync2
python3 main.py

Evaluation Agent endpoints

### POST /approve
**params**
	poolAddress: str
  borrowerWalletAddress: str

**Result**
{
    "creditLimit": 300000000,
    "intervalInDays": 30,
    "remainingPeriods": 12,
    "aprInBps": 0
}

### POST /underwrite
**params**
	poolAddress: str
  borrowerWalletAddress: str
  creditLimit: float

**Result** 
{
    "creditLimit": 300000000,
    "intervalInDays": 30,
    "remainingPeriods": 12,
    "aprInBps": 0
}

Calls to Signal Adapters

### API call for signal retrieval from Stripe
curl -X 'POST' \
  'http://127.0.0.1:8000/fetch' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "signal_names": [
    "stripe_adapter.total_balance"
  ],
  "adapter_inputs": {"stripe_api_key": "sk_test_4eC39HqLyjWDarjtT1zdp7dc"}
}'

### API call for signal retrieval from Circle
curl -X 'POST' \
  'http://127.0.0.1:8000/fetch' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "signal_names": [
    "circle_adapter.account_balance"
  ],
  "adapter_inputs": {"account": "circle_71283"}
}'

### API call for signal retrieval from Spectral
curl -X 'POST' \
  'http://localhost:8000/fetch' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "signal_names": [
    "spectral_adapter.score"
  ],
  "adapter_inputs": {"wallet": "0x573d19B66Cdc33f7E751f2a478ECeCe95155e798", "token":"SFMyNTY.g2gDbQAAACQ3MGY1ZDgxMC0yMjk1LTQyMjQtODA1Zi01ZGNmNzMxYzY3YTBuBgBspGeWhgFiAAFRgA.ruwaqqurFh6PCDUhY0z0TNmiWiqrmp8ZOmG3--bksSM"}
}'

### API call for signal retrieval from Flock
curl -X 'POST' \
  'http://localhost:8000/fetch' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "signal_names": [
    "flock_adapter.prediction"
  ],
   "adapter_inputs": {
    "input_array": [
        12000.0,
        36,
        10.78,
        98000.0,
        24.04,
        0.0,
        694.0,
        0.0,
        15.0,
        1.0,
        20462.0,
        62.8,
        39.0,
        1349.67,
        0.0,
        0.0,
        7884.96,
        754.0,
        0.0,
        0.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0,
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        1,
        0
    ]
}
}'

ZKSync deployment

ZKSync chain and smart contracts

# close git repot
gh repo clone credit-wallet/joey-mono
# Start the local nodes

### install Docker first

### To run zkSync locally, run the start.sh script:
cd zkchain-setup
./start.sh

### deploy smart contracts on zksync
gh repo clone credit-wallet/huma-contracts-zk
cd huma-contracts-zk
yarn hardhat run scripts/deploy.ts --network zkTestnet

Signal Adapters

# Signal Adapters API server
cd joey-mono/signal-adapters

# install poetry
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
poetry install

# run the server
make run-local

Evaluation Agent

# Start the EvaluationAgent service: 
cd joey-mono/evaluation-agent
pip install git+https://github.com/zksync-sdk/zksync-python.git
pip3 install -r requirements.txt
pip install zksync2
python3 main.py

Setup Metamask

### Local L1 network
### Network Name: L1 local
New RPC URL: http://localhost:8545/
Chain ID: 9
Currency Symbol: ETH
Local zkSync network

### Network Name: L2 local zkSync
New RPC URL: http://localhost:3050/
Chain ID: 270
Currency Symbol: ETH

Update for ZK

### evaluation agent, huma_pool.py
self.w3 = Web3(HTTPProvider("http://0.0.0.0:3050"))

### metamask
### Network Name: L2 local zkSync
New RPC URL: http://localhost:3050/
Chain ID: 270
Currency Symbol: ETH

Deployed contracts on zkSync Era Goerli

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •