Smart Contracts
Technical specifications for the RevvFi core smart contracts.
RevvFiArchController
Protocol-wide registry of approved borrowers, approved assets/oracles, and deployed markets.
registerBorrower(address)/removeBorrower(address)— owner-gated borrower whitelistisRegisteredBorrower(address)— used by the Factory to gate market deploymentisBlacklistedAsset(address)— checked against borrow asset, collateral asset, and oracle at deploy time
RevvFiFactory
The entry point for deploying a new market.
deployMarket(address borrower, address borrowAsset, address collateralAsset, address collateralOracle, uint8 collateralDecimals, uint8 borrowDecimals, uint256 minCollateralRatio, uint256 liquidationThreshold)— clones and wires a new Market + CollateralEscrow + OfferBook + LiquidityQueue forborrower, gated onArchController.isRegisteredBorrower. Requires payment ofdeploymentFee.setDeploymentFee(uint256)/setFeeRecipient(address)— owner-onlysetCoreContracts(...)— wires the shared PositionNFT/Liquidator/ReputationRegistry addresses once at protocol setup
RevvFiMarket
The primary interaction point for a single borrower and their lenders.
Position State (per position ID)
positionPrincipal— the position’s actual owed principal, independent of any other positionpositionApr— the APR this specific position accrues atpositionLastAccrualTime— last time interest was rolled into principal for this positionpositionSeniority,positionActive,positionSettled,positionClaimableAmount
Core Functions
depositCollateral(uint256 amount)/withdrawCollateral(uint256 amount)borrow(uint256 amount, bool useSeniorOnly, uint256 maxApr)— fills the request from the OfferBook, mints a position NFT per lender filledrepay(uint256 amount)— partial repayment, split across active positions proportional to each one’s own share of total debtrepayFull()— settles every active position at onceclaimFunds(uint256 positionId)— pull-based; lender withdraws their credited claimable balancegetTotalOwed()/getCurrentPrincipal()— sum of all active positions’ debt/principalgetPositionValue(uint256 positionId)/getPositionClaimable(uint256 positionId)
RevvFiCollateralEscrow
Holds a market’s collateral and prices it via Chainlink.
depositCollateral(address borrower, uint256 amount)/withdrawCollateral(...)— callable only by the associated MarketstalePriceThreshold— per-market oracle staleness window (default 24h), tunable viasetStalePriceThreshold(uint256)(factory-only)getCollateralRatio(address, uint256 debt)/isHealthy(...)/isLiquidatable(...)— read the current Chainlink price and compare againstminCollateralRatio/liquidationThresholdsetMinCollateralRatio(uint256)/setLiquidationThreshold(uint256)— factory-only
RevvFiOfferBook
Order book of lender offers for one market.
submitOffer(uint256 amount, uint256 apr, uint8 seniority, uint256 duration)—seniority:0= senior,1= juniorcancelOffer(uint256 offerId)/modifyOffer(uint256 offerId, uint256 newAmount, uint256 newApr, uint256 newDuration)getBestOffers(uint256 amount, bool useSeniorOnly)— sorts all active offers by APR ascending (across both seniority tiers) and fills up toamount;useSeniorOnlyis a borrower-selectable filter, not an automatic priority tiercleanupExpiredOffers(uint256 maxCleanup)— permissionless housekeeping for expired offers
RevvFiPositionNFT
ERC-721 representing a lender’s claim on a specific market.
- Minted by a Market on
borrow(), one NFT per lender filled - Encodes principal, APR, seniority, and market association
- Burned/redeemed on full settlement
RevvFiLiquidator
Runs liquidation auctions across every market.
createAuction(...)— called by a Market when a position is liquidatable; starting price = 100% of debt, reserve price = 80% of debtplaceBid(uint256 auctionId, uint256 bidAmount)— first bid must meet the current declining price; subsequent bids must exceed the previous highest byminBidIncrementBps(1% default)settleAuction(uint256 auctionId)— callable afterendTime; pays the market (for lender distribution) and transfers collateral to the winner. Auto-retries with a fresh auction if no bids were received.- Auction parameters:
auctionDuration(3 days default),dutchAuctionStepDuration(1 hour default),dutchAuctionPriceDecrementBps(5% per step default),auctionExtensionWindow(15 minutes)
ReputationRegistry
Protocol-wide borrower reputation, independent of any single market.
| Field | Description |
|---|---|
successfulLoans | Incremented on each fully-repaid loan |
defaultedLoans | Incremented on each liquidation-triggered default |
reputationScore | (successfulLoans * 1000 / totalLoans) - (defaultedLoans * 50), clamped to [0, 1000]; 500 if the borrower has no loan history yet |
| Score Range | Risk Label |
|---|---|
| 900–1000 | AAA |
| 800–899 | AA |
| 700–799 | A |
| 500–699 | B |
| 300–499 | C |
| 0–299 | D |
Next Steps
- Review Architectural Decisions for the reasoning behind these designs
- Explore Data Structures for full struct layouts
- Check Reference → Events for the complete event log