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

MintingOfInput #44

Open 123456788940 opened 1 year ago

123456788940 commented 1 year ago

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

import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

contract USDTpeggedToken is ERC20, Ownable { using ECDSA for bytes32;

address public reserveAddress;
mapping(address => bool) public authorizedAddresses; // Mapping of authorized addresses

constructor(address _reserveAddress) ERC20("INPUTToken", "INT") {
    reserveAddress = _reserveAddress;
    authorizedAddresses[msg.sender] = true; // Initialize the deployer as an authorized address
}

modifier onlyAuthorized() {
    require(authorizedAddresses[msg.sender], "Unauthorized address");
    _;
}

function mint(uint256 amount, bytes32 messageHash, bytes memory signature) external onlyAuthorized {
    require(amount > 0, "Amount must be greater than 0");
    require(reserveAddress != address(0), "Reserve address not set");

    address signer = messageHash.recover(signature);
    require(signer == owner(), "Invalid signature");

    _mint(msg.sender, amount);
}

function setReserveAddress(address _reserveAddress) external onlyOwner {
    reserveAddress = _reserveAddress;
}

function addAuthorizedAddress(address _address) external onlyOwner {
    authorizedAddresses[_address] = true;
}

}

123456788940 commented 1 year ago

USDTpeggedToken Smart Contract

The USDTpeggedToken is a Solidity smart contract that represents an ERC-20 token with minting functionality, cryptographic signature verification, and an authorization system to restrict minting to specific addresses. This token is pegged to a value similar to 1 USD.

Overview

The contract is built using the OpenZeppelin library and inherits from ERC20 and Ownable contracts. It includes cryptographic features for verifying the authenticity of minting requests using digital signatures. Additionally, it features an authorization system that ensures only specific addresses are allowed to perform minting.

Contract Details

Constructor

The contract is deployed with the following parameters:

Functions

  1. mint(uint256 amount, bytes32 messageHash, bytes memory signature)

    • Allows authorized addresses to mint tokens against stablecoins in the reserve using a cryptographic signature.
    • Requirements:
      • amount must be greater than 0.
      • reserveAddress must be set.
      • The caller must be an authorized address.
      • The provided signature must be valid and correspond to the contract owner's signature on the messageHash.
    • Mints an equivalent amount of tokens to the caller if the signature is valid.
  2. setReserveAddress(address _reserveAddress)

    • Allows the contract owner to set or update the reserve address.
    • Requirements:
      • Caller must be the contract owner.
    • Updates the reserveAddress to the provided address.
  3. addAuthorizedAddress(address _address)

    • Allows the contract owner to add an address to the list of authorized addresses.
    • Requirements:
      • Caller must be the contract owner.
    • Grants the specified address authorization to mint tokens.

Usage

  1. Deploy the USDTpeggedToken contract by providing the initial reserve address.

  2. Once the contract is deployed, authorized addresses can be added using the addAuthorizedAddress function.

  3. Authorized addresses can then mint tokens using the mint function by signing a unique messageHash and providing the corresponding signature.

  4. The contract owner can update the reserve address using the setReserveAddress function and manage the list of authorized addresses using addAuthorizedAddress.

    Note

Please tailor this README document to match your specific project's requirements and provide users with clear instructions on how to interact with your smart contract.