Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
myenv/
node_modules/
package-lock.json
package-lock.json
.DS_Store
144 changes: 144 additions & 0 deletions contracts/core/stablecoin/AccessController.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

// Importing the necessary libraries
import "@openzeppelin/contracts/access/Ownable.sol"; // Importing the Ownable contract from OpenZeppelin

/**
* @title AccessController
* @dev This contract manages access control for the stablecoin system.
*/
contract AccessController is Ownable {
// State variables of the contract
bool public mintPaused; // Flag to pause minting (0 = not paused(active), 1 = paused)
bool public burnPaused; // Flag to pause burning (0 = not paused(active), 1 = paused)
// Flag to indicate if the contract is in emergency mode (0 = not in emergency mode, 1 = in emergency mode)
bool public emergencyMode;


// Events

/**
* @notice Emitted when minting is paused or unpaused
* @dev This is fired during the setMintPaused function
* @param status True if minting is paused, false otherwise
*/
event MintPaused(bool status);

/**
* @notice Emitted when burning is paused or unpaused
* @dev This is fired during the setBurnPaused function
* @param status True if burning is paused, false otherwise
*/
event BurnPaused(bool status);

/**
* @notice Emitted when the contract is paused
* @dev This is fired during the setEmergencyMode function
* @param timestamp The timestamp when the contract was paused
*/
event EmergencyShutdown(uint256 timestamp);

// constructor to initialize the access controller
constructor() Ownable(msg.sender) {
mintPaused = false; // Initialize minting as not paused
burnPaused = false; // Initialize burning as not paused
emergencyMode = false; // Initialize emergency mode as not active
}

/**
* @notice Checks if minting is allowed
* @dev This function returns true if minting is not paused and not in emergency mode
* @return bool True if minting is allowed, false otherwise
*/
function canMint(address) external view returns (bool) {
return !mintPaused && !emergencyMode; // Check if minting is allowed
}

/**
* @notice Checks if burning is allowed
* @dev This function returns true if burning is not paused and not in emergency mode
* @return bool True if burning is allowed, false otherwise
*/
function canBurn(address) external view returns (bool) {
return !burnPaused && !emergencyMode; // Check if burning is allowed
}

/**
* @notice Checks if pausing is allowed
* @dev This function returns true if the caller is the owner
* @param caller The address of the caller
* @return bool True if pausing is allowed, false otherwise
*/
function canPause(address caller) external view returns (bool) {
return caller == owner(); // Check if the caller is the owner
}

/**
* @notice Checks if unpausing is allowed
* @dev This function returns true if the caller is the owner and not in emergency mode
* @param caller The address of the caller
* @return bool True if unpausing is allowed, false otherwise
*/
function canUnpause(address caller) external view returns (bool) {
return caller == owner() && !emergencyMode; // Check if the caller is the owner and not in emergency mode
}

/**
* @notice Checks if emergency shutdown is allowed
* @dev This function returns true if the caller is the owner
* @param caller The address of the caller
* @return bool True if emergency shutdown is allowed, false otherwise
*/
function canEmergencyShutdown(address caller) external view returns (bool) {
return caller == owner(); // Check if the caller is the owner
}

/**
* @dev Pause or start minting
* @param _statusMinting true to pause minting, false to start minting
*/
function setMintPaused(bool _statusMinting) external onlyOwner {
// Check if the new minting status is different from the current minting status
// This prevents unnecessary updates which could lead to gas wastage
require(_statusMinting != mintPaused, "New minting status must be different from current minting status");
mintPaused = _statusMinting; // Set the minting status
emit MintPaused(_statusMinting); // Emit the event
}

/**
* @dev Pause or start burning
* @param _statusBurning true to pause burning, false to start burning
*/
function setBurnPaused(bool _statusBurning) external onlyOwner {
// Check if the new burning status is different from the current burning status
// This prevents unnecessary updates which could lead to gas wastage
require(_statusBurning != burnPaused, "New burning status must be different from current burning status");
burnPaused = _statusBurning; // Set the burning status
emit BurnPaused(_statusBurning); // Emit the event
}

/**
* @dev Set the emergency mode status
* @param _statusEmergency true to set emergency mode, false to unset emergency mode
*/
function setEmergencyMode(bool _statusEmergency) external onlyOwner {
// Check if the new emergency status is different from the current emergency status
// This prevents unnecessary updates which could lead to gas wastage
require(_statusEmergency != emergencyMode,
"New emergency status must be different from current emergency status");
emergencyMode = _statusEmergency; // Set the emergency mode status

if (_statusEmergency) {
if(!mintPaused) {
mintPaused = true; // Set minting to paused
emit MintPaused(mintPaused); // Emit the event
}
if(!burnPaused) {
burnPaused = true; // Set burning to paused
emit BurnPaused(burnPaused); // Emit the event
}
emit EmergencyShutdown(block.timestamp); // Emit the event
}
}
}
91 changes: 91 additions & 0 deletions contracts/core/stablecoin/FeeManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

// Importing the necessary libraries
import "@openzeppelin/contracts/access/Ownable.sol"; // Importing the Ownable contract from OpenZeppelin

/**
* @title FeeManager
* @dev This contract manages the fees for a stablecoin system.
*/
contract FeeManager is Ownable {
// State variables of the contract
uint256 public stabilityFee; // Fee charged on minting (in basis points)
uint256 public redemptionFee; // Fee charged on redemption (in basis points)

// Constants
uint256 private constant BASIS_POINTS = 10000; // Basis points constant for calculations

/**
* @notice Emitted when the stability fee is updated
* @dev This is fired during the updateStabilityFee function
* @param newStabilityFee The new fee applied for stability maintenance
*/
event StabilityFeeUpdated(uint256 newStabilityFee);

/**
* @notice Emitted when the redemption fee is updated
* @dev This is fired during the updateRedemptionFee function
* @param newRedemptionFee The new fee applied when redeeming collateral
*/
event RedemptionFeeUpdated(uint256 newRedemptionFee);

// Constructor to initialize the FeeManager contract
constructor() Ownable(msg.sender) {
stabilityFee = 50; // Initial stability fee set to 0.5%
redemptionFee = 30; // Initial redemption fee set to 0.3%
}

/**
* @dev Calculate the mint fee (Stability Fee) based on the amount
* @param amount The amount to be minted
* @return amountAfterFee The amount after the stability fee is deducted
* @return feeAmount The amount of the stability fee charged
*/
function calculateMintFee(uint256 amount) external view returns (uint256 amountAfterFee, uint256 feeAmount) {
feeAmount = (amount * stabilityFee) / BASIS_POINTS; // Calculate the fee amount
amountAfterFee = amount - feeAmount; // Calculate the amount after fee deduction
}

/**
* @dev Calculate the redemption fee based on the amount
* @param amount The amount to be redeemed
* @return amountAfterFee The amount after the redemption fee is deducted
* @return feeAmount The amount of the redemption fee charged
*/
function calculateRedemptionFee(uint256 amount) external view returns (uint256 amountAfterFee, uint256 feeAmount) {
feeAmount = (amount * redemptionFee) / BASIS_POINTS; // Calculate the fee amount
amountAfterFee = amount - feeAmount; // Calculate the amount after fee deduction
}

/**
* @dev Update the stability fee
* @param _newStabilityFee New stability fee (in basis points)
*/
function updateStabilityFee(uint256 _newStabilityFee) external onlyOwner {
// Check if the new stability fee is valid (>0) and is at most 10% (1000 basis points)
require(_newStabilityFee > 0 && _newStabilityFee <= 1000, "Stability fee must be between 0 and 10%");
// Check if the new stability fee is different from the current stability fee
// This prevents unnecessary updates which could lead to gas wastage
require(_newStabilityFee != stabilityFee, "New stability fee must be different from current stability fee");

stabilityFee = _newStabilityFee; // Update the stability fee
emit StabilityFeeUpdated(_newStabilityFee); // Emit the event
}

/**
* @dev Update the redemption fee
* @param _newRedemptionFee New redemption fee (in basis points)
*/
function updateRedemptionFee(uint256 _newRedemptionFee) external onlyOwner {
// Check if the new redemption fee is valid (>0) and is at most 5% (500 basis points)
require(_newRedemptionFee > 0 && _newRedemptionFee <= 500, "Redemption fee must be between 0 and 5%");
// Check if the new redemption fee is different from the current redemption fee
// This prevents unnecessary updates which could lead to gas wastage
require(_newRedemptionFee != redemptionFee, "New redemption fee must be different from current redemption fee");

redemptionFee = _newRedemptionFee; // Update the redemption fee
emit RedemptionFeeUpdated(_newRedemptionFee); // Emit the event
}

}
Loading
Loading