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

Write a Foundation Treasury Pool Smart contract #31

Open shivasai780 opened 1 year ago

shivasai780 commented 1 year ago

The Foundation Treasury Pool Contract is responsible for

Taking Care of investments that the committee does and investors

123456788940 commented 1 year ago

// SPDX-License-Identifier: MIT pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract FoundationTreasuryPool is Ownable, ReentrancyGuard { address public treasuryWallet; uint256 public totalCollateral;

mapping(address => uint256) public protocolInvestments;

constructor(address _treasuryWallet) {
    treasuryWallet = _treasuryWallet;
}

function participateInNetworkElections(uint256 amount) external nonReentrant { // Ensure the amount is valid and within 10% of the treasury pool require(amount > 0 && amount <= (totalCollateral / 10), "Invalid amount");

// Transfer |V1 GOV| tokens from the sender to this contract
require(IERC20(treasuryWallet).transferFrom(msg.sender, address(this), amount), "Transfer failed");

// Add the participant's collateral to the protocol investments
protocolInvestments[msg.sender] += amount;

}

function divertSlashedTokensToTreasury(address token, uint256 amount) external onlyOwner {
    require(amount > 0, "Invalid amount");

    // Transfer slashed tokens to the Treasury
    IERC20(token).transferFrom(msg.sender, address(this), amount);
}

 // Allow anyone to send funds in the form of stablecoins to the Treasury
 event StablecoinsReceived(address, address, uint);
function sendStablecoinsToTreasury(address token, uint256 amount) external nonReentrant {
    require(token != address(0), "Invalid token address");
    require(amount > 0, "Invalid amount");

    IERC20(token).transferFrom(msg.sender, address(this), amount);
    emit StablecoinsReceived(msg.sender, token, amount);
}

}

WeuFoundDev commented 1 year ago

add the function docs too

123456788940 commented 1 year ago

Foundation Treasury Pool Smart Contract

SPDX-License-Identifier: MIT

Overview

The FoundationTreasuryPool smart contract is a decentralized financial solution designed to manage and utilize funds within a foundation or organization. It provides functionalities for participating in network elections, diverting slashed tokens to the treasury, and receiving stablecoins. This document provides a high-level description of the contract's key features and functions.

Contract Details

State Variables

Constructor

Functions

  1. participateInNetworkElections(uint256 amount): Allows participants to invest collateral for network elections. The invested amount must be valid and within 10% of the total collateral.

  2. divertSlashedTokensToTreasury(address token, uint256 amount): Allows the contract owner to divert slashed tokens to the treasury. Slashed tokens are transferred to the contract.

  3. sendStablecoinsToTreasury(address token, uint256 amount): Allows anyone to send stablecoins to the treasury. Stablecoins are transferred to the contract.

Events

Usage

  1. Deploy the FoundationTreasuryPool contract by providing the address of the treasury wallet.
  2. Participants can use the participateInNetworkElections() function to invest collateral for network elections, ensuring the amount is within the specified limits.
  3. The contract owner can divert slashed tokens to the treasury using the divertSlashedTokensToTreasury() function.
  4. Anyone can send stablecoins to the treasury using the sendStablecoinsToTreasury() function.
shivasai780 commented 1 year ago

Please Check this

//**
 * @title FDV - Foundation  Contract
 * @dev This smart contract manages funds for protocols and users, facilitating investment 
 * The contract is owned by an address and can only be interacted with by designated parties.
 * It allows protocols to send investments, manage their funding details, and transfer amounts to a burning contract.
 * Only the designated foundation (multisig)address is allowed to trigger transfers to the burning contract.
 */
pragma solidity ^0.8.16;

import "./IBurning.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract FDV is Ownable {
    // Struct to store investment details for each protocol
    struct Protocol {
        uint Investments;           // Total investments received for the protocol
        uint AmountTransferred;     // Total amount transferred to the burning contract
        address UsdUsed;            // Address of the USD token used for investments
    }

    mapping(address => Protocol) public Details; // Protocol-specific investment details
    mapping(address => uint) public UserAmount;  // User-specific received amounts
    mapping (address =>uint )public  SlashedAmount; //Slashed Amount 

    IBurning public BurningAddress;     // Address of the Burning contract
    address public WeuFoundation;       // Address of the foundation managing the contract

    // Modifier to ensure that only the foundation can execute certain functions
    modifier onlyWeuFoundation() {
        require(msg.sender == WeuFoundation, "Only the foundation can call this function");
        _;
    }

    /**
     * @dev Receives an investment for a protocol.
     * @param _Protocol Address of the protocol sending the investment.
     * @param _amount Amount of the investment.
     * @param usdUsed Address of the USD token used for the investment.
     */
    function ReceiveInvestment(address _protocol, uint _amount, address usdUsed) external {
        require(_protocol != address(0), "Protocol address must not be zero");
        require(BurningAddress.UsdUsed(usdUsed) == true, "Token is not registered");

        Details[_protocol].Investments += _amount;
        Details[_protocol].UsdUsed = usdUsed;

        IERC20(usdUsed).transferFrom(msg.sender, address(this), _amount);
    }

    /**
     * @dev Sets the address of the burning contract.
     * @param _burningAddress Address of the burning contract.
     */
    function SetBurningAddress(address _burningAddress) external onlyOwner {
        require(_burningAddress != address(0), "Burning address cannot be zero");
        BurningAddress = IBurning(_burningAddress);
    }

    /**
     * @dev Receives an amount from a user.
     * @param usdUsed Address of the USD token used for the transaction.
     * @param _amount Amount received from the user.
     */
    function ReceiveAmount(address usdUsed, uint _amount) external {
        require(usdUsed != address(0), "USD address must not be zero");
        require(_amount > 0, "Received amount must be greater than zero");

        UserAmount[msg.sender] += _amount;
        IERC20(usdUsed).transferFrom(msg.sender, address(this), _amount);
    }

    /**
     * @dev Receives an amount from a user for slashed tokens.
     * @param usdUsed Address of the USD token used for the transaction.
     * @param _amount Amount received from the user.
     */

    function ReceiveSlashedTokensToTreasury(address usdUsed, uint256 amount) external onlyOwner {
    require(amount > 0, "Invalid amount");
    SlashedAmount[UsdUsed]=amount;

    // Transfer slashed tokens to the Treasury
    IERC20(usdUsed).transferFrom(msg.sender, address(this), amount);
    }

    /**
     * @dev Transfers an amount to the burning contract for a protocol.
     * @param _protocol Address of the protocol to transfer funds from.
     * @param _amount Amount to be transferred.
     */
    function TransferToBurning(address _protocol, uint _amount) external onlyWeuFoundation {
        require(_protocol != address(0), "Protocol address must not be zero");
        require((_amount + Details[_protocol].AmountTransferred) <= Details[_protocol].Investments);

        if (BurningAddress.getProtocolInitiated(_protocol) == true) {
            IERC20(Details[_protocol].UsdUsed).approve(address(BurningAddress), _amount);
            BurningAddress.addAmountToBurningPool(_protocol, _amount);
            Details[_protocol].AmountTransferred += _amount;
        } else {
            IERC20(Details[_protocol].UsdUsed).approve(address(BurningAddress), _amount);
            BurningAddress.initializeBurningPool(_protocol, Details[_protocol].UsdUsed, _amount);
            Details[_protocol].AmountTransferred += _amount;
        }
    }

    /**
     * @dev Sets the address of the foundation managing the contract.
     * @param _weuFoundation Address of the foundation.
     */
    function setWeuFoundation(address _weuFoundation) external onlyOwner {
        require(_weuFoundation != address(0), "Foundation address cannot be zero");
        WeuFoundation = _weuFoundation;
    }

}
WeuFoundDev commented 1 year ago

check in participatory slash stake vault

shivasai780 commented 1 year ago

The FDV (Foundation Contract) is a Solidity smart contract designed to manage funds for investment protocols and users within a decentralized finance (DeFi) ecosystem. This contract is owned by an address and can be interacted with by designated parties. It facilitates investment processes, manages investment details for protocols, and allows the transfer of amounts to a burning contract. The contract also implements role-based access control, where only the designated foundation address is allowed to trigger specific functions.

Contract Structure

The FDV contract is structured into different sections, each serving a specific purpose:

Struct Protocol

The Protocol struct holds investment details for each protocol. It includes:

Contract Variables

Modifiers

Constructor

The contract constructor initializes the contract owner, set to be the address deploying the contract.

Contract Functions

The FDV contract defines several functions to manage investments, transfers, and protocol-related operations:

ReceiveInvestment(address _protocol, uint _amount, address usdUsed)

This function allows protocols to send investments to the contract. It records investment details and the associated USD token. Only protocols can call this function.

SetBurningAddress(address _burningAddress)

Sets the address of the burning contract that will be interacted with for burning tokens. Only the contract owner can set this address.

ReceiveAmount(address usdUsed, uint _amount)

Receives an amount from a user and records it in the UserAmount mapping. The user's USD token used for the transaction must be specified.

ReceiveSlashedTokensToTreasury(address usdUsed, uint256 amount)

Receives slashed tokens from the foundation and transfers them to the contract. The foundation must specify the amount and the USD token used for the transaction.

TransferToBurning(address _protocol, uint _amount)

Transfers an amount to the burning contract for a protocol. The foundation can call this function to transfer funds from a specific protocol to the burning contract. It checks whether the protocol's burning pool is initialized and interacts with the burning contract accordingly.

setWeuFoundation(address _weuFoundation)

Sets the address of the foundation managing the contract. Only the contract owner can set this address.

Modifiers and Role-Based Access Control

The FDV contract implements role-based access control using the onlyWeuFoundation modifier. This modifier ensures that certain functions can only be called by the designated foundation address (WeuFoundation).