Skip to content

Commit

Permalink
Smart Contract 0.7.3
Browse files Browse the repository at this point in the history
STEEZFacet.sol and SteezFeesFacet.sol are mostly finished. Now shifting focus to STEELOFacet and getting distracted with cross-facet fixes like SteezGov and Profile.
  • Loading branch information
EdmundBerkmann committed Mar 1, 2024
1 parent 055dc97 commit 7aca941
Show file tree
Hide file tree
Showing 7 changed files with 3,817 additions and 667 deletions.
9 changes: 9 additions & 0 deletions contracts/facets/features/ProfileFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ contract ProfileFacet is IProfileFacet, ERC1155Upgradeable, OwnableUpgradeable,
emit ProfileUpdated(user);
}

function verifyCreator(/* Creator data */) public {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
STEEZFacet.Steez memory localSteez = STEEZFacet(ds.steezFacetAddress).steez(creatorId);
// Verification logic here

localSteez.creatorId++; // Increment the creatorId
localSteez.steez[creatorId] = /* new Creator */;
}

// Function to check if a username already exists
function usernameTaken(string memory username) internal view returns (bool) {
return usernameExists[username];
Expand Down
161 changes: 78 additions & 83 deletions contracts/facets/steelo/STEELOFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ import "@openzeppelin/contracts/utils/Strings.sol";
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

contract STEELOFacet is
ERC20,
OwnableUpgradeable,
PausableUpgradeable,
ReentrancyGuard,
ChainlinkClient {

contract STEELOFacet is ERC20, OwnableUpgradeable, PausableUpgradeable, ReentrancyGuard, ChainlinkClient {
STEEZFacet.Steez public steez;
STEEZFacet.Investor public investor;
using LibDiamond for LibDiamond.DiamondStorage;

// Events
Expand All @@ -28,35 +24,22 @@ contract STEELOFacet is
event BurnRateUpdated(uint256 newBurnRate);
event steeloTGEExecuted(uint256 tgeAmount);

// Storage

mapping(uint256 => uint256) private _mintedInLastYear;
int256 steezTransactionCount;
uint256 steeloCurrentPrice;
uint256 steezCurrentPrice;
uint256 totalMinted;
uint256 totalBurned;
uint256 lastMintEvent;
uint256 lastBurnUpdate;
uint256 mintAmount;
uint256 burnAmount;
uint256 burnRate;
uint256 mintRate;
bool isDeflationary;
bool tgeExecuted;

function initialize(
address _treasury,
address _oracle,
string memory _jobId,
uint256 _fee,
address _linkToken
) public initializer {
int256 public steezTransactionCount = -1e9;
uint256 public steeloCurrentPrice;
uint256 public totalMinted;
uint256 public totalBurned;
uint256 public lastMintEvent;
uint256 public lastBurnEvent;
uint256 public mintAmount;
uint256 public burnAmount;
uint256 private burnRate;
uint256 private mintRate;
bool public isDeflationary;
bool public tgeExecuted;

function initialize(address _treasury, address _oracle, string memory _jobId, uint256 _fee, address _linkToken) public initializer {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
__ERC20_init("Steelo", "STEELO");
__OwnableUpgradeable_init();
__PausableUpgradeable_init();
__ReentrancyGuard_init();
ERC20("Steelo", "STEELO");

require(_treasury != address(0), "Treasury cannot be the zero address");

Expand All @@ -72,13 +55,15 @@ contract STEELOFacet is
}

// Function to mint tokens dynamically based on $Steez transactions and current price
function steeloTGE(uint256 _steezTransactions, uint256 _currentPrice) external onlyOwner nonReentrant {
function steeloTGE(uint256 _steeloCurrentPrice) external onlyOwner nonReentrant {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
STEEZFacet.Steez memory localSteez = STEEZFacet(ds.steezFacetAddress).steez(creatorIdId);
require(!ds.tgeExecuted, "steeloTGE can only be executed once");
require(_steezTransactions > 0, "_steezTransactions must be greater than 0");
require(_currentPrice > 0, "_currentPrice must be greater than 0");
require(localSteez.transactionCount == 0, "steezTransactionCount must be equal to 0");
require(steeloCurrentPrice > 0, "steeloCurrentPrice must be greater than 0");
require(totalSupply() == ds.TGE_AMOUNT, "steeloTGE can only be called for the Token Generation Event");

uint256 tgeAmount = calculateMintAmount(_steezTransactions, _currentPrice); // This function may also need adjustment
uint256 tgeAmount = calculateMintAmount(localSteez.steezTransactionCount, steeloCurrentPrice); // This function may also need adjustment

// Calculate distribution amounts using ds references for percentages
uint256 communityAmount = (tgeAmount * ds.communityTGE) / 100;
Expand All @@ -92,18 +77,30 @@ contract STEELOFacet is
_mint(ds.earlyInvestorsAddress, earlyInvestorsAmount);
_mint(ds.treasury, treasuryAmount);

ds.tgeExecuted = true; // Update the flag in the shared storage
tgeExecuted = true; // Update the flag in the shared storage
emit TokensMinted(ds.treasury, tgeAmount);
emit steeloTGEExecuted(tgeAmount); // Emit an event for the TGE execution
}

function calculateTotalTransactions() public {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
STEEZFacet.Steez memory localSteez = STEEZFacet(ds.steezFacetAddress).steez(creatorId);
uint256 totalTransactions = 0;
for (uint256 i = 0; i < localSteez.steezIds.length; i++) {
totalTransactions += STEEZFacet(address(this)).steez(localSteez.steezIds[i]).transactionCount;
}
steezTransactionCount += int256(totalTransactions); // Make sure to cast totalTransactions to int256

// Check if steezTransactionCount has reached 0 and transition to deflationary system
if (steezTransactionCount >= 0) {
// Transition to deflationary system
}
}

// Override the _transfer function to mint tokens automatically
function _transfer(address sender, address recipient, uint256 amount) internal override nonReentrant {
super._transfer(sender, recipient, amount);
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();

// Only mint tokens if the system is in the deflationary phase
if (ds.isDeflationary) {
if (isDeflationary) {
burnAmount = calculateBurnAmount(amount); // Calculate the amount to burn
_burn(sender, burnAmount);
}
Expand All @@ -122,61 +119,69 @@ contract STEELOFacet is
_transfer(msg.sender, ds.steeloAddress, feeAmount);
}

// Unified minting function
function steeloMint(uint256 _steezTransactions, uint256 _currentPrice) external onlyOwner nonReentrant {
function steeloMint() external onlyOwner nonReentrant {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
require(totalSupply() > ds.TGE_AMOUNT, "steeloMint can only be called after the TGE");
require(_steezTransactions > 0, "_steezTransactions must be greater than 0");
require(_currentPrice > 0, "_currentPrice must be greater than 0");
require(steezTransactionCount > 0, "steezTransactionCount must be greater than 0");
require(steeloCurrentPrice > 0, "steeloCurrentPrice must be greater than 0");

mintAmount = calculateMintAmount(_steezTransactions, _currentPrice);
distributeMintedTokens(mintAmount);
uint256 steeloMintAmount = calculateMintAmount(steezTransactionCount, steeloCurrentPrice);

// Calculate distribution amounts using ds references for percentages
uint256 treasuryAmount = (steeloMintAmount * ds.treasuryMint) / 100;
uint256 liquidityProvidersAmount = (steeloMintAmount * ds.liquidityProvidersMint) / 100;
uint256 ecosystemProvidersAmount = (steeloMintAmount * ds.ecosystemProvidersMint) / 100;

// Mint tokens directly to addresses
_mint(ds.treasury, treasuryAmount);
_mint(ds.liquidityProviders, liquidityProvidersAmount);
_mint(ds.ecosystemProviders, ecosystemProvidersAmount);
}

// Calculates the amount to mint based on transaction count and current price
function calculateMintAmount(uint256 _steezTransactions, uint256 _currentPrice) public view returns (uint256) {
function calculateMintAmount() public view returns (uint256) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
uint256 adjustmentFactor = 1 ether;
if (_currentPrice >= ds.pMax) {
adjustmentFactor += (_currentPrice - ds.pMax) * ds.alpha / 100;
} else if (_currentPrice <= ds.pMin) {
adjustmentFactor -= (ds.pMin - _currentPrice) * ds.beta / 100;
if (steeloCurrentPrice >= ds.pMax) {
adjustmentFactor += (steeloCurrentPrice - ds.pMax) * ds.alpha / 100;
} else if (steeloCurrentPrice <= ds.pMin) {
adjustmentFactor -= (ds.pMin - steeloCurrentPrice) * ds.beta / 100;
} else {
adjustmentFactor += adjustmentFactor / 100; // 1% adjustment when Pcurrent is within Pmin and Pmax
}
mintAmount = ds.rho * _steezTransactions * adjustmentFactor / 1 ether / 1 ether;
mintAmount = ds.rho * steezTransactionCount * adjustmentFactor / 1 ether / 1 ether;
return mintAmount;
}

// Calculate the Supply Cap to use in the minting function
function calculateSupplyCap(uint256 _currentPrice) public view returns (uint256) {
function calculateSupplyCap() public view returns (uint256) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
uint256 currentSupply = totalSupply();
uint256 supplyCap;
if (_currentPrice < ds.pMin) {
supplyCap = currentSupply - ds.delta * (ds.pMin - _currentPrice) * currentSupply / 1 ether;
if (steeloCurrentPrice < ds.pMin) {
supplyCap = currentSupply - ds.delta * (ds.pMin - steeloCurrentPrice) * currentSupply / 1 ether;
} else {
supplyCap = currentSupply; // maintain the current supply cap if Pcurrent is within or above the target range
}
return supplyCap;
}

// Function to calculate the amount to burn based on the burn rate
function calculateBurnAmount(uint256 amount) private view returns (uint256) {
function calculateBurnAmount() private view returns (uint256) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return amount * ds.burnRate / 10000; // Using ds.burnRate
return amount * burnRate / 10000; // Using ds.burnRate
}

// Function to adjust the mint rate, can be called through governance decisions (SIPs)
function adjustMintRate(uint256 _newMintRate) external onlyOwner nonReentrant {
function adjustMintRate() external onlyOwner nonReentrant {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
require(_newMintRate > 0 && _newMintRate <= ds.mintRateMax, "Invalid mint rate");
ds.mintRate = _newMintRate;
emit MintRateUpdated(_newMintRate);
}

// Function to adjust the burn rate, can be called through governance decisions (SIPs)
function adjustBurnRate(uint256 _newBurnRate) external onlyOwner nonReentrant {
function adjustBurnRate() external onlyOwner nonReentrant {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
require(_newBurnRate > 0 && _newBurnRate <= ds.burnRateMax, "Invalid burn rate");
ds.burnRate = _newBurnRate;
Expand All @@ -193,8 +198,8 @@ contract STEELOFacet is
require(burnAmount > 0, "Burn amount must be greater than 0");

_burn(address(this), burnAmount); // Assuming _burn requires an address argument
ds.totalBurned += burnAmount;
ds.lastBurnUpdate = block.timestamp;
totalBurned += burnAmount;
lastBurnEvent = block.timestamp;

emit TokensBurned(burnAmount);
}
Expand All @@ -204,40 +209,30 @@ contract STEELOFacet is
return owner();
}

// Function to update the transaction count and possibly trigger burning
function updateSteezTransactionCount(uint256 _mintAmount) external onlyOwner nonReentrant {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
ds.steezTransactionCount += _mintAmount;
if (!ds.isDeflationary && ds.steezTransactionCount > 0) {
ds.isDeflationary = true;
}
if (ds.steezTransactionCount >= ds.BURN_THRESHOLD) {
burnTokens();
}
}

// Example function to update transaction volume and current price
function updateParameters(uint256 _steezTransactionCount, uint256 _currentPrice) external {
function updateParameters() external {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
require(_currentPrice >= ds.pMin && _currentPrice <= ds.pMax, "Price out of allowed range");
ds.steezTransactionCount = _steezTransactionCount;
ds.steeloCurrentPrice = _currentPrice;
require(steeloCurrentPrice >= ds.pMin && steeloCurrentPrice <= ds.pMax, "Price out of allowed range");
ds.steezTransactionCount = steezTransactionCount;
ds.steeloCurrentPrice = steeloCurrentPrice;
// Logic to determine if minting or burning should occur based on updated parameters
}

// Function to make a GET request to the Chainlink oracle
function requestVolumeData() public returns (bytes32 requestId) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
Chainlink.Request memory request = buildChainlinkRequest(ds.jobId, address(this), this.fulfill.selector);
req.add("get", "https://us-central1-steelo.io.cloudfunctions.net/functionName");
req.add("path", "volume");
return sendChainlinkRequestTo(ds.oracle, request, ds.fee);
}

// Function to receive the response from the Chainlink oracle
function fulfill(bytes32 _requestId, uint256 _steezTransactionCount) public recordChainlinkFulfillment(_requestId) {
function fulfill(bytes32 _requestId) public recordChainlinkFulfillment(_requestId) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
require(_steezTransactionCount > 0, "Invalid transaction count");
ds.steezTransactionCount = _steezTransactionCount;
require(steezTransactionCount > 0, "Invalid transaction count");
ds.steezTransactionCount = steezTransactionCount;
// Additional logic for mint or burn based on the new transaction count
}

Expand Down
Loading

0 comments on commit 7aca941

Please sign in to comment.