CredX is a decentralized credit protocol built on Solana that allows users to deposit staked tokens (mSOL/jitoSOL) as collateral to borrow Credit Tokens. The borrowed amount is based on live Oracle price feeds, and loan repayments are automated using the yield generated from the staked collateral.
- Deposit yield-bearing staked tokens (mSOL / jitoSOL) as collateral
- Borrow Credit Tokens based on live LTV ratio and Oracle prices
- Daily/Weekly cron job to repay loans using staking yield
- Oracle integration via Pyth Network
- Fully automated loan lifecycle with secure PDAs
-
Admin Initializes Protocol
- Deploys and initializes the protocol state
- Creates the Credit Token mint account
-
User Initializes Protocol (Loan Position)
- A new user loan position is created
- Initializes:
- Collateral Vault PDA
- Loan Account PDA
- Credit Token Account
-
Deposit Collateral
- User deposits mSOL/jitoSOL to the Collateral Vault PDA
- Deposit data is updated in the Loan Account PDA
-
Get Oracle Price
- Real-time price fetched from the Pyth Oracle for mSOL/jitoSOL
-
Lend Credit Token
- Borrowable Credit =
LTV * Oracle Price * Deposited Collateral - Credit Token is minted to user’s Credit Token Account
- Borrowable Credit =
-
Automated Repayment by Cron Job
- Periodic job runs (daily/weekly)
- Fetches yield from staked tokens
- Calculates equivalent credit value using Oracle
- Repays by:
- Burning user's Credit Token
- Reducing debt in Loan Account PDA
-
Withdraw Collateral
- If outstanding debt = 0
- Transfers staked token back to user
- Closes Loan Account PDA
| # | Instruction | Description |
|---|---|---|
| 1 | initializeProtocol |
Admin sets up the protocol, credit mint, and configuration |
| 2 | initializeUserLoan |
User sets up their vault, loan account, and credit account |
| 3 | depositCollateral |
Transfers mSOL/jitoSOL from user to Vault PDA |
| 4 | getOraclePrice |
Uses Pyth to fetch current staked token price |
| 5 | lendCreditToken |
Calculates LTV-based borrow amount and mints Credit Tokens |
| 6 | cronRepayment |
Uses yield from staked collateral to repay loan periodically |
| 7 | withdrawCollateral |
Allows withdrawal of collateral if loan is fully repaid |
| State Account | Description |
|---|---|
ProtocolState |
Stores protocol-level config (admin, LTV ratio, credit mint, etc.) |
CollateralVaultPDA |
Stores user's deposited staked tokens |
LoanAccountPDA |
Stores user’s loan data (collateral amount, borrowed, repaid, etc.) |
CreditMintPDA |
Mint account for the Credit Token |
CreditAccount |
User’s token account holding minted Credit Tokens |
- Solana
- Anchor
- Pyth Oracle
- SPL Token Program
To run and test locally:
anchor build
anchor test