Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🪙 Denari Protocol

Denari (DNR) is a decentralized, exogenous, crypto-collateralized, algorithmic stablecoin pegged to the U.S. Dollar (USD).
It is inspired by DAI, designed for simplicity, security, and extensibility.


📘 Overview

The Denari Protocol consists of two main smart contracts:

  1. Denari.sol — ERC20 token contract representing the Denari stablecoin (DNR).
  2. DNREngine.sol — Core engine that manages collateral deposits, stablecoin minting/burning, redemptions, and liquidations.

The system uses crypto assets (wETH and wBTC) as collateral and maintains stability through overcollateralization and on-chain Chainlink oracles.


⚙️ Architecture

Contract Responsibility
Denari.sol ERC20-compliant token representing DNR, controlled by DNREngine. Handles minting/burning.
DNREngine.sol Core protocol logic — manages collateral, debt positions, redemptions, and liquidations.
OracleLib.sol Library for Chainlink price feeds with staleness protection.
HelperConfig.s.sol Deployment configuration for Anvil, Sepolia, and Mainnet.
DeployDNR.s.sol Script to deploy protocol and link ownership between contracts.
DNREngineTest.t.sol Foundry test suite ensuring correctness and stability.

🏗️ System Design

Properties

  • Exogenous — backed by external crypto assets (wETH / wBTC)
  • Anchored — 1 DNR = 1 USD target peg
  • Decentralized — no centralized control
  • Overcollateralized — ensures solvency during volatility
  • Algorithmic — minting/burning governed by protocol rules

Collateral Types

  • wETH
  • wBTC

Collateralization Parameters

Parameter Value Description
Liquidation Threshold 50% 200% collateralization required
Liquidation Bonus 10% Incentive for liquidators
Minimum Health Factor 1.0 Below this, liquidation is allowed

🧮 Core Functions

🏦 Deposit Collateral

Users deposit wETH or wBTC to mint DNR. Each collateral type has an associated Chainlink price feed.

dnrEngine.depositCollateral(weth, 1 ether);

💵 Mint DNR

After depositing sufficient collateral, users can mint Denari stablecoins up to their available limit.Minting automatically checks the user’s health factor — users cannot mint if it drops below the minimum.

dnrEngine.mintDNR(2000e18);

🔥 Burn DNR

Users burn their DNR to reduce debt and reclaim collateral.

dnrEngine.burnDNR(amount);

💰 Redeem Collateral

After burning sufficient DNR, users can withdraw their collateral.

dnrEngine.redeemCollateral(weth, amount);

⚔️ Liquidate

When a user’s health factor falls below 1.0, their position becomes liquidatable. Liquidators can repay a portion of their DNR debt to seize collateral at a 10% discount.

dnrEngine.liquidate(user, weth, amountDNRToBurn);

🧱 Liquidation Flow Summary

Step Description Function
1 Deposit collateral (wETH / wBTC) depositCollateral()
2 Mint DNR mintDNR()
3 Price drop simulation updateAnswer()
4 Check health factor getHealthFactor()
5 Liquidate unhealthy position liquidate()
6 Verify solvency getHealthFactor()

🧠 Health Factor

The Health Factor (HF) indicates how safe a user's position is. Screenshot 2025-10-10 at 14 57 43

If HF >= 1.0 → safe position

If HF < 1.0 → subject to liquidation


🚀 DeployDNR.s.sol

This Foundry deployment script handles the automated deployment of the Denari Protocol core contracts —
the Denari (DNR) stablecoin and the DNREngine — along with environment configuration via HelperConfig.s.sol.


📄 Script Overview

File: script/DeployDNR.s.sol
Purpose: Deploys the core Denari Protocol contracts with the correct collateral and price feed setup.

🔧 Contracts Deployed

Contract Description
Denari.sol ERC20 stablecoin implementation (DNR).
DNREngine.sol Core logic handling collateral, minting, burning, and liquidation.
HelperConfig.s.sol Provides environment-specific configuration such as price feeds, collateral tokens, and deployer key.

🧠 How It Works

The script:

  1. Loads network-specific configuration from HelperConfig.s.sol (e.g., WETH, WBTC, and Chainlink feeds).
  2. Sets up arrays for token addresses and price feed addresses.
  3. Deploys the Denari contract.
  4. Deploys the DNREngine contract with the deployed tokens and feeds.
  5. Transfers ownership of the Denari stablecoin to the engine.
  6. Returns all deployed contract addresses.

🧩 Contract Flow

HelperConfig
     ↓
Provides WETH/WBTC + Price Feeds
     ↓
DeployDNR.s.sol
     ↓
Deploys Denari.sol and DNREngine.sol
     ↓
Transfers Denari ownership → DNREngine

🧩 Returned Values

When executed, the script returns:

(DNREngine dnrEngine, Denari dnr, HelperConfig helperConfig)

📜 License

MIT License © 2025 Developed by Conrad Japhet

About

An exogenous, algorithmic ERC-20 stablecoin pegged to USD

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages