Contract Architecture
The protocol consists of several core contracts that work together to provide lending functionality:
Core Contracts
Nectra.sol
The main contract that inherits from all other functionality contracts
Handles position creation, modification, and management
Key functions:
modifyPosition
: Create, modify, or close a positionquoteModifyPosition
: Get a quote for position modificationupdatePosition
: Update position state with the latest interest
NectraLiquidate.sol
Handles position liquidation
Implements:
Partial liquidation
Full liquidation
Liquidator rewards
Key functions:
liquidate
: Partially liquidate an undercollateralized positionfullLiquidate
: Fully liquidate a severely undercollateralized position
NectraRedeem.sol
Handles redemption of nUSD for collateral
Implements:
Dynamic redemption fees
Bucket-based redemption
Redemption buffer management
Key functions:
redeem
: Redeem nUSD for collateral_redeemFromBuckets
: Internal redemption logic_calculateRedemptionFeeAndUpdateBuffer
: Fee calculation
NectraFlash.sol
Handles flash loans and flash mints
Implements:
Flash loan cBTC functionality
Flash mint nUSD functionality
Circuit breaker protection
Key functions:
flashLoan
: Execute a flash loanflashMint
: Execute a flash mint_requireFlashBorrowUnlocked
: Circuit breaker check
NectraNFT.sol
ERC721 token representing positions
Handles position ownership and permissions
Key functions:
mint
: Create a new positionauthorize
: Grant permission to manage the positionrevoke
: Revoke position management permission
NUSDToken.sol
ERC20 token representing borrowed nUSD
Implements minting and burning with access control
Key functions:
mint
: Create new nUSD tokensburn
: Destroy nUSD tokenspermit
: Gasless approvals
OracleAggregator.sol
Price feed aggregation
Provides:
Collateral price updates
Price staleness checks
Fallback oracle support
Key functions:
getLatestPrice
: Get the most recent valid price_tryGetPrice
: Internal price fetching with staleness check_normalize
: Normalize price to 18 decimals
Supporting Contracts
NectraBase.sol
Base contract containing shared state and constants
Defines core data structures:
Globals
: System-wide stateBucket
: Interest rate bucket statePosition
: Individual position state
NectraLib.sol
Core library for state management and calculations
Handles:
Position and bucket state updates
Interest calculations
Debt share conversions
Liquidation calculations
NectraMathLib.sol
Mathematical operations library
Provides:
Share/asset conversions
Safe math operations
Bit searching utilities
NectraViews.sol
Read-only functions for querying protocol state
Key functions:
getPosition
: Get position collateral and debtgetBucketState
: Get bucket stategetGlobalState
: Get system-wide statecanLiquidate
: Check liquidation eligibility