Skip to main content

State Schema

GHOST stores all protocol state in MongoDB via Mongoose models. This page documents each model's fields, types, and relationships.

DepositSlot

Tracks a lender's deposit from initialization through confirmation or expiry.

FieldTypeDescription
slotIdstringUnique identifier
userIdstringLender's Ethereum address (lowercased)
tokenstringToken address being deposited
amountstringDeposit amount (BigInt as string)
statusstringpending, confirmed, or cancelled
encryptedRatestringECIES encrypted rate (set on confirm)
intentIdstringAssociated lend intent ID (set on confirm)
epochIdstringEpoch in which the slot was created
createdAtDateCreation timestamp

Slots expire after 10 minutes if not confirmed. The expireOldSlots function runs periodically to clean these up.

LendIntent

Represents a confirmed lending position with an encrypted rate bid.

FieldTypeDescription
intentIdstringUnique identifier
userIdstringLender's Ethereum address (lowercased)
tokenstringToken address
amountstringLending amount (BigInt as string)
encryptedRatestringECIES encrypted rate (hex string)
epochIdstringAssociated epoch

Lend intents are consumed when they are included in an accepted match proposal. A single intent can be partially consumed across multiple proposals.

BorrowIntent

Represents a borrower's request for funds with collateral.

FieldTypeDescription
intentIdstringUnique identifier
borrowerstringBorrower's Ethereum address (lowercased)
tokenstringToken to borrow
amountstringBorrow amount (BigInt as string)
encryptedMaxRatestringMaximum acceptable rate (encrypted)
collateralTokenstringCollateral token address
collateralAmountstringCollateral offered (BigInt as string)
statusstringpending, proposed, matched, cancelled, or rejected

Status transitions: pending -> proposed (when CRE generates proposal) -> matched (when proposal accepted) or rejected (when proposal rejected) or cancelled (user cancellation).

MatchProposal

A match generated by the CRE matching engine.

FieldTypeDescription
proposalIdstringUnique identifier
borrowIntentIdstringReference to the borrow intent
borrowerstringBorrower's address
tokenstringLending token
principalstringTotal matched amount (BigInt as string)
matchedTicksarrayArray of MatchedTick objects
effectiveBorrowerRatenumberWeighted average rate
collateralTokenstringCollateral token
collateralAmountstringTotal collateral
statusstringpending, accepted, rejected, or expired
expiresAtDateDeadline for borrower response

MatchedTick

Each matched tick within a proposal:

FieldTypeDescription
lenderstringLender's address
lendIntentIdstringReference to the lend intent
amountstringAmount filled from this tick (BigInt as string)
ratenumberThe decrypted rate for this tick

Loan

An active, repaid, or defaulted loan.

FieldTypeDescription
loanIdstringUnique identifier
borrowerstringBorrower's address
tokenstringLending token
principalstringTotal loan amount (BigInt as string)
matchedTicksarrayArray of MatchedTick objects
effectiveBorrowerRatenumberBlended rate
collateralTokenstringCollateral token
collateralAmountstringTotal collateral posted
requiredCollateralstringMinimum required collateral at creation
maturityDateLoan maturity date
statusstringactive, repaid, or defaulted
repaidAmountstringAmount repaid (BigInt as string)

PendingTransfer

A queued fund movement waiting for CRE execution.

FieldTypeDescription
idstringUnique identifier
recipientstringDestination address
tokenstringToken to transfer
amountstringTransfer amount (BigInt as string)
reasonstringTransfer reason (see Transfer Reasons)
createdAtDateWhen the transfer was queued
statusstringpending or completed

Balance

Internal balance tracking for each user and token pair.

FieldTypeDescription
addressstringUser's Ethereum address (lowercased)
tokenstringToken address
amountstringCurrent balance (BigInt as string)

Balances are modified via creditBalance and debitBalance helper functions that perform atomic updates.

CreditScore

Endogenous credit scoring for each user.

FieldTypeDescription
addressstringUser's Ethereum address (lowercased)
tierstringbronze, silver, gold, or platinum
loansRepaidnumberCount of successfully repaid loans
loansDefaultednumberCount of defaulted loans

New users are initialized at { tier: "bronze", loansRepaid: 0, loansDefaulted: 0 }.

State Helpers

The state.ts module exports helper functions for common state operations:

FunctionDescription
queueTransfer(params)Create a pending transfer record
creditBalance(address, token, amount)Increase a user's balance
debitBalance(address, token, amount)Decrease a user's balance
getBalance(address, token)Fetch current balance
getCreditScore(address)Fetch or initialize credit score
upgradeTier(address)Move credit tier up one level
downgradeTier(address)Move credit tier down one level
getCollateralMultiplier(tier)Return the multiplier for a tier
expireOldSlots()Clean up deposit slots older than 10 minutes