WeuFoundDev / Governance-token-contracts

Governance contract of INPUT (INT) | A development based minting tokens for developers and researchers ecosystem.
GNU General Public License v3.0
2 stars 0 forks source link

GDV pool #38

Open 123456788940 opened 1 year ago

123456788940 commented 1 year ago

// 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;

uint256 public redemptionValue;
uint256 public timechainSlotDuration;
uint256 public inputsRemaining;
uint256 public timechainSlotsAvailable;

mapping(address => uint256) public balances;

modifier onlyCommittee() {
    require(
        msg.sender == technicalCommittee || msg.sender == researchCommittee,
        "Only technical and research committee can call this function"
    );
    _;
}

constructor(
    address _technicalCommittee,
    address _researchCommittee,
    address _glvAddress,
    address _inaccessibleAddress,
    address _intTokenAddress,
    uint256 _redemptionValue,
    uint256 _timechainSlotDuration,
    uint256 _inputsRemaining,
    uint256 _timechainSlotsAvailable
) {
    owner = msg.sender;
    technicalCommittee = _technicalCommittee;
    researchCommittee = _researchCommittee;
    glvAddress = _glvAddress;
    inaccessibleAddress = _inaccessibleAddress;
    intTokenAddress = _intTokenAddress;
    redemptionValue = _redemptionValue;
    timechainSlotDuration = _timechainSlotDuration;
    inputsRemaining = _inputsRemaining;
    timechainSlotsAvailable = _timechainSlotsAvailable;
}

function mintTokens(uint256 amount) external {
    require(inputsRemaining >= amount, "Not enough inputs remaining");
    balances[msg.sender] += amount;
    inputsRemaining -= amount;
}

function redeemTokens(uint256 amount) external onlyCommittee {
    require(amount > 0, "Amount must be greater than zero");
    uint256 stableValue = (amount * redemptionValue) / 1e18;
    ERC20(intTokenAddress).transfer(msg.sender, stableValue);
    balances[msg.sender] -= amount;
    balances[inaccessibleAddress] += amount;
}

function burnAndPayout(uint256 amount) external onlyCommittee {
    uint256 burnedAmount = (amount * 2) / 100;
    balances[msg.sender] -= burnedAmount;
    balances[inaccessibleAddress] += burnedAmount;
    ERC20(intTokenAddress).transfer(glvAddress, burnedAmount);
}

function transferStablecoinsToGLV() external onlyCommittee {
    IERC20(intTokenAddress).transfer(glvAddress, balances[address(this)]);
}

function updateRedemptionValue(uint256 _newRedemptionValue) external onlyCommittee {
    redemptionValue = _newRedemptionValue;
}

function updateTimechainSlotDuration(uint256 _newTimechainSlotDuration) external onlyCommittee {
    timechainSlotDuration = _newTimechainSlotDuration;
}

function updateInputsRemaining(uint256 _newInputsRemaining) external onlyCommittee {
    inputsRemaining = _newInputsRemaining;
}

function updateTimechainSlotsAvailable(uint256 _newTimechainSlotsAvailable) external onlyCommittee {
    timechainSlotsAvailable = _newTimechainSlotsAvailable;
}

}

shivasai780 commented 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);
     }
}
WeuFoundDev commented 1 year ago

is this doc @123456788940 is based on shiv code or on ur code . Make improvements and submit it by tomorrow @shivasai780 @123456788940

shivasai780 commented 1 year ago

Remove automated minting creation code

shivasai780 commented 1 year ago

Write the functionality to claim at 8am every 7 the day

shivasai780 commented 1 year ago

Write the funcitonaly to send to 2% to glv pool at 12 pm

WeuFoundDev commented 1 year ago

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

  1. 5 point is irrevalent - Creating Timechains and Pools - what are gdv , glv tokens . dont use ai for god sake
  2. It intiate to reedeem in 6th point , devs can reedem stable for INT at the end of every timechain . UTC 8.00 am
  3. Token Burning and Payout - third point in this what is the function , and INT tokens be burned every 5 timechains
  4. sixth - 5 point is shit as you always use ai - soham please .......
  5. what stablecoin threshold you are talking every timechain 2 percent get trans to GLV and if the protocol reaches mainnet stage , multi sig can send all the stables to GLV . @123456788940 @shivasai780
WeuFoundDev commented 1 year ago

and i cant see a single function related to the contract in this document .

123456788940 commented 1 year ago

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

  1. Ownership and Committee Addresses:

    • The contract is deployed with specified committee addresses: technical committee and research committee.
    • The deployer is not the owner of the GDVPool contract.
  2. Stablecoins Supported:

    • The contract supports the "INT" stablecoin, represented by the ERC20 token standard.
  3. Redemption and Minting:

    • Users can mint new "INT" tokens by providing appropriate collateral.
    • Technical and research committee members can redeem "INT" tokens for stablecoins based on a specified redemption value.
  4. Token Burning and Payout:

    • The contract allows for burning a portion of "INT" tokens (e.g., 2% of total supply) by the committee.
    • Burned "INT" tokens are transferred to an inaccessible address.
    • The equivalent value in stablecoins is transferred to the GDV Governance Vault (GLV) address.
  5. Transfer to GLV:

    • A fixed percentage (2%) of stablecoins is automatically transferred to the GDV GLV address in each timechain period.
    • At the mainnet stage, a multi-signature wallet can send all stables to the GLV address.
  6. Timechain Slot Management:

    • The contract manages timechain slots, allowing users to initiate redemption at specific time intervals (e.g., every week) at UTC 8:00 am.
  7. Dynamic Parameters:

    • The contract allows for dynamic updates of key parameters such as redemption value, timechain slot duration, inputs remaining, and timechain slots available.

Usage Instructions

  1. Minting Tokens:

    • Users can mint "INT" tokens by providing collateral and calling the mintTokens function.
  2. Redeeming Tokens:

    • Committee members can redeem "INT" tokens for stablecoins by calling the redeemTokens function.
  3. Burning and Payout:

    • Committee members can burn "INT" tokens and transfer stablecoin equivalents to the GLV address using the burnAndPayout function.
  4. Transfer to GLV:

    • Committee members can transfer a fixed percentage (2%) of stablecoins to the GLV address using the transferStablecoinsToGLV function.
  5. Parameter Updates:

    • Committee members can update parameters such as redemption value, timechain slot duration, inputs remaining, and timechain slots available using respective update functions.