Open 123456788940 opened 1 year ago
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./Iint.sol";
import "./Minting.sol";
import "./IMinting.sol";
import "./IGLVault.sol"
import "./GLVault.sol";
contract TimechainProtocol is ReentrancyGuard{
// Define the structure for the protocol's
struct Protocol {
uint256 Investments;//total Number of investment came
uint256 timeChainsLeft;//No of timechains left
mapping(uint=>mapping(uint=>uint)) slashingPercentage;//slashingpercent[number of investment][Amount]=slashpercent
mapping(uint => uint)amountStaked;//Investment number-->amount staked
address Mintingaddress;//Minting address for the specific protocol
uint256 noOfinvestments;//No of times the investments came for this Protocol
address usdUsed;// the usd token used to funcd for this protocol
uint256 startingBlock;//block number when protocol is started
uint256 TimechainsBurnedInt;//until how many timechains the int had been burned
uint256 totalslashedAmount;//how much amount had been slashed from this investment
address Glvaddress;//Glp address for this protocol
bool initiated;//is the Protocol is initiated
uint256 IntAccumulated;//the total int accumulated for this protocl
uint256 IntBurned;//the total amount of int burned for protocl until now
uint256 LastTimechainBurnedInt;//time when the last int burning took place
uint256 FundsFromGlp;//Funds that are returned by glv pool
uint256 FundsReceivedTime;//Time when the funds have been received
uint256 LastTimeIntBurned;//Last time the int tokens had been burned
uint256 LastTimeSlashedAmount;//Last time the tokens are slashed
}
// Mapping to store the protocol's data
mapping(address => Protocol) public Protocols;
//Mapping to store the glip pools data
// GLIPs vault to hold the slashed INT
// mapping(address => uint256) public GLVaultAmount;
address public USDT;//stable coin1
address public USDC;//stable coin2
address public DAI;//stable coin3
Iint public intToken;//int token address
address public owner;//Owner address
address public WeuFoundation;//multisig contract address
address public TreasuryPool;//Treasury pool address
//initialization function
constructor(address _USDT,address _USDC,address _DAI,address _intToken,address weuFoundation,address _treasuryPool) {
USDT = _USDT;
USDC=_USDC;
DAI=_DAI;
intToken=Iint(_intToken);
WeuFoundation= weuFoundation;
owner = msg.sender;
TreasuryPool =_treasuryPool;
}
//modifier to check whether the caller is owner or not
modifier onlyOwner() {
require(msg.sender == owner, "Only the owner can perform this action");
_;
}
//modifier to check wherther the caller is weufoundation or not
modifier onlyWeuFoundation(){
require(msg.sender == WeuFoundation,"The owner needs to be only weo fundation");
_;
}
//modifier to check wherther the caller is weufoundation or not
modifier onlyTreasury(){
require(msg.sender == TreasuryPool,"The owner needs to be only weo fundation");
_;
}
//This event is emitted whenever we receive the amount from the glp pool
event ReceivedFundsFromGlp(address _protocol,uint _amount);
/**
* @dev This function is called by treary pool to send funds for the specific protocol for the first time
* @param _Protocol Address of the protocol sending the investment.
* @param usdUsed Address of the USD token used for the investment.
* @param _totalamount Amount of the investment.
*/
function initializeProtocol(address _protocolAddress,address usdUsed,uint _totalamount) external nonReentrant onlyTreasury{
require(_protocolAddress!=address(0),"The address cannot be equal to zero address");
require(usdUsed != address(0),"the address cannot be equal to zero address");
require(_totalamount != 0,"the given amount cannot be equal to zero ");
require(Protocols[_protocolAddress].Investments == 0, "Burning pool already initialized");
require(Protocols[_protocolAddress].noOfinvestments == 0,"The pool is already initialized");
require(usdUsed == USDT || usdUsed == USDC || usdUsed ==DAI ,"The tokem used should be any one of them");
Protocols[_protocolAddress].Investments=_totalamount;
Protocols[_protocolAddress].timeChainsLeft=50;
Protocols[_protocolAddress].slashingPercentage[1][_totalamount]=2;
Protocols[_protocolAddress].noOfinvestments=1;
Protocols[_protocolAddress].amountStaked[1]=_totalamount;
Protocols[_protocolAddress].usdUsed=usdUsed;
Protocols[_protocolAddress].startingBlock = block.timestamp;
Protocols[_protocolAddress].LastTimechainBurnedInt = block.timestamp;
Protocols[_protocolAddress].initiated = true;
//create a Glip pool for this protocol
GLVault glip=new GLVault();
address Glvaddress=address(glip);
IGLVault(glip).initialize(address(this),WeuFoundation,_protocolAddress);
Protocols[_protocolAddress].Glvaddress=Glvaddress;
//transfer the usd to this account,before that he need to give the approval for this contract
IERC20(usdUsed).transferFrom(msg.sender,address(this),_totalamount);
}
/**
@dev Update Minting Contract
*/
function UpdateMintingContract(address _protocoladdress,address _mintingContract)external nonReentrant onlyWeuFoundation{
require(_mintingContract != address(0),"Minting address cannot be equal to zero");
require(_protocoladdress != address(0),"Minting address cannot be equal to zero");
IGLVault(Protocols[_protocoladdress].Glvaddress).UpdateMintingAddress(_mintingContract);
}
/**
* @dev This function is called by treary pool to send funds for the specific protocol if the protocol is also present
* @param _Protocol Address of the protocol sending the investment.
* @param _totalamount Amount of the investment.
*/
function addAmountToProtocol(address _protocolAddress,uint _totalamount) external nonReentrant onlyTreasury{
require(_protocolAddress!=address(0),"The address cannot be equal to zero address");
require(_totalamount != 0,"the given amount cannot be equal to zero ");
Protocol storage pool = Protocols[_protocolAddress];
require(pool.noOfinvestments != 0,"The no of investments cannot be equal to zero ");
require(pool.Mintingaddress != address(0),"The pool Haven't initialized");
// Calculate the slashing percentage for the new supply of INT
uint256 slashingPercentage = 100 / pool.timeChainsLeft;
// Update the Burning pool data with the new inputs and slashing percentage
pool.Investments += _totalamount;
pool.noOfinvestments +=1;
pool.amountStaked[pool.noOfinvestments]=_totalamount;
pool.slashingPercentage[pool.noOfinvestments][_totalamount]=slashingPercentage;
IMinting(pool.Mintingaddress).InceaseMaxSupply(_totalamount);
IERC20(pool.usdUsed).transferFrom(msg.sender,address(this),_totalamount);
}
/**
* @dev This function is called For slashing Tokens it will called in the backend
* @param _Protocol Address of the protocol sending the investment.
* @param _percent Passing the Percent of the slashing amount.
*/
function slashTokens(address _protocolAddress,uint[] memory _percent) external nonReentrant{
require(_protocolAddress!=address(0),"The address cannot be equal to zero address");
Protocol storage pool = Protocols[_protocolAddress];
require(pool.timeChainsLeft > 0,"The Timechains needs to be greater than 0");
require(pool.LastTimeSlashedAmount );
// uint completedTimeChains= (block.timestamp - pool.startingBlock)/7 days;
// uint FinalTimeChainLeft=completedTimeChains-(50-pool.timeChainsLeft);
// for(uint i= 0 ;i<=pool.noOfinvestments;i++)
// {
// uint amountstaked=pool.amountStaked[i+1];
// // Calculate the slashed amount for this period
// slashedAmount += (amountstaked * (pool.slashingPercentage[i+1][amountstaked]* completedTimeChains)) / 100;
// }
uint256 slashedAmount;
for(uint i=0;i< _percent.length;i++)
{
uint amountstaked=pool.amountStaked[i+1];
// Calculate the slashed amount for this period
slashedAmount += ((amountstaked * (_percent[i])) / 100)
}
// Update the Burning pool's total inputs after slashing
pool.totalslashedAmount += slashedAmount;
// Add the slashed amount to the GLIPs vault
// GLVaultAmount[msg.sender] += slashedAmount;
IERC20(pool.usdUsed).approve(GLVault,slashedAmount);
IGLVault(pool.Glvaddress).ReceiveAmount(slashedAmount,pool.usdUsed);
// Decrease the number of timechains left
pool.timeChainsLeft -= 1;
//send the amount to the GLVault
IERC20(pool.usdUsed).transfer(GLVault,slashedAmount);
IMinting(pool.Mintingaddress).decreaseMaxminted(slashedAmount);
}
/**
* @dev This function gives the present available amount for the protocol excluding the slashing amount
* @param _Protocol Address of the protocol .
*/
function getBalance(address _protocolAddress) external view returns (uint256) {
require(_protocolAddress!=address(0),"The address cannot be equal to zero address");
Protocol storage pool = Protocols[_protocolAddress];
return pool.Investments - pool.totalslashedAmount;
}
/**
* @dev This function is for the developers who will burn the int tokens and get the equavalent stable token coin
* @param _Protocol Address of the protocol .
* @amount amount to be transffered
*/
function burnandClaim(address _protocol,uint256 amount) external nonReentrant {
require(amount!=0,"The address cannot be equal to zero address");
require(intToken.balanceOf(msg.sender)>= amount,"Not Sufficient Amount in your wallet");
require(IERC20(USDT).balanceOf(address(this))>=amount || IERC20(USDC).balanceOf(address(this))>=amount || IERC20(DAI).balanceOf(address(this))>=amount );
Protocol storage pool = Protocols[_protocolAddress];
require((block.timestamp - pool.LastTimeIntBurned) >= 7 days,"The timechain had till not completed");
address currentStableCoin = findGreatest(USDT, USDC, DAI);
pool.IntAccumulated +=amount;
pool.LastTimeIntBurned = block.timestamp;
intToken.transferFrom(msg.sender,address(this),amount);
IERC20(currentStableCoin).transfer(msg.sender,amount);
}
/**
* @dev This function is to check whether the usd coin is accepted by this contract or not
* @param _usdused usd token address
*/
function UsdUsed(address _usdused)public view returns(bool)
{
require(_usdused != address(0),"The address cannot be equak to the zero address");
if(_usdused == USDT || _usdused ==USDC || _usdused == DAI)
{
return true;
}
else{
return false;
}
}
/**
* @dev This is internal function to check which usd tokens has the highest value in this contract
*/
function findGreatest(address _USDT,address _USDC,address _DAI) public view returns (address) {
// Using if-else statements
address greatestCoin;
if ( IERC20(_USDT).balanceOf(address(this))>= IERC20(_USDC).balanceOf(address(this)) && IERC20(_USDT).balanceOf(address(this)) >= IERC20(_DAI).balanceOf(address(this)) ) {
greatestCoin = _USDT;
} else if (IERC20(_USDC).balanceOf(address(this)) >= IERC20(_USDT).balanceOf(address(this)) && IERC20(_USDC).balanceOf(address(this)) >= IERC20(_DAI).balanceOf(address(this))) {
greatestCoin = _USDC;
} else{
greatestCoin = _DAI;
}
return greatestCoin;
}
/**
* @dev This function is to check whether the protocol is initialized or not
*/
function getProtocolInitiated(address _protocol)public view returns(bool)
{
return Protocols[_protocol].initiated;
}
/**
* @dev This function is called by weu foundation to burn the int tokens every 5 timechains
*@param _protocol address of the protocol
*/
function burnINT(address _protocol)public onlyWeuFoundation{
require(_protocol != address(0),"the protocol address cannot be equal to 0");
Protocol storage pool = Protocols[_protocolAddress];
require(block.timestamp - pool.LastTimechainBurnedInt >= 5 weeks,"The burn can only happen for every 5 weeks");
require(pool.TimechainsBurnedInt <= 50,"There are only 50 Timechains");
uint balance=intToken.balanceOf(address(this));
if(balance >0)
{
intToken.burn(balance);
}
pool.TimechainsBurnedInt +=5;
pool.LastTimechainBurnedInt = block.timestamp;
}
/**
@dev This function is called by the Glp pool whenit wasrequested for the 1/4 of extra amount to build the protocol
@param _protocol Address of the protocol
*/
function RequestAmount(address _protocol)public onlyWeuFoundation
{
require(_protocol != address(0),"protocol address cannot be zero address");
Protocol storage pool = Protocols[_protocol];
uint AmountBefore= GLVault(pool.Glvaddress).ProtocolAmount(_protocol);
uint Actualamount=(AmountBefore/4)
IGLVault(pool.Glvaddress).sendAmount(pool.usdUsed);
uint AmountAfter= GLVault(pool.Glvaddress).ProtocolAmount(_protocol);
require((AmountBefore-Actualamount) == AmountAfter,"The Amounts are not matched");
pool.FundsFromGlp +=Actualamount;
pool.FundsReceivedTime=block.timestamp;
emit ReceivedFundsFromGlp(_protocol,Actualamount);
}
/**
@dev This function will resend the amount tp glip pool after the 1/4 of the timechain means 12.5 time chains
@param _protocol Address of the protocol
*/
function TransferFundsBackToGlp(address _Protocol)public onlyWeuFoundation
{
require(_Protocol != address(0),"The protocol address cannot be equal to zero");
Protocol storage pool = Protocols[_Protocol];
uint PresenAmount=(pool.FundsFromGlp-IERC20(pool.usdUsed).balanceOf(address(this));
pool.FundsFromGlp +=Actualamount;
IGLVault(pool.Glvaddress).ReceiveAmount(_Protocol,PresenAmount,pool.usdUsed);
}
}
is this doc @123456788940 is based on shiv code or on ur code . Make improvements and submit it by tomorrow @shivasai780 @123456788940
Remove automated minting creation code
Write the functionality to claim at 8am every 7 the day
Write the funcitonaly to send to 2% to glv pool at 12 pm
1.Deployer address will not be the owner of GDV POOL ,that will be the technical and research committee addresses . 2.mention the stablecoins name - USDT, USDC , DAI
and i cant see a single function related to the contract in this document .
GDVPool: Decentralized Finance Contract for Stablecoin Management
The GDVPool contract is a decentralized finance (DeFi) smart contract that facilitates the management of stablecoins, particularly the "INT" token, within a secure and transparent environment. This contract allows for minting, redeeming, burning, and transferring of stablecoins, all governed by a technical and research committee.
Contract Features
Ownership and Committee Addresses:
Stablecoins Supported:
Redemption and Minting:
Token Burning and Payout:
Transfer to GLV:
Timechain Slot Management:
Dynamic Parameters:
Usage Instructions
Minting Tokens:
mintTokens
function.Redeeming Tokens:
redeemTokens
function.Burning and Payout:
burnAndPayout
function.Transfer to GLV:
transferStablecoinsToGLV
function.Parameter Updates:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract GDVPool { address public owner; address public technicalCommittee; address public researchCommittee; address public glvAddress; address public inaccessibleAddress; address public intTokenAddress;
}