Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MintingOfInput #44

Open
123456788940 opened this issue Aug 27, 2023 · 1 comment
Open

MintingOfInput #44

123456788940 opened this issue Aug 27, 2023 · 1 comment
Labels
review Review is used by var/core contributor in order to finalise it before even deploytestnet function

Comments

@123456788940
Copy link
Collaborator

123456788940 commented Aug 27, 2023

// 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
Copy link
Collaborator Author

123456788940 commented Aug 27, 2023

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:

  • address _reserveAddress: The initial address of the stablecoin reserve.

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

  • Cryptographic signatures provide a secure authorization mechanism for minting actions.
  • Ensure only authorized addresses are added and that private keys are kept secure.

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.

@123456788940 123456788940 added the review Review is used by var/core contributor in order to finalise it before even deploytestnet function label Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Review is used by var/core contributor in order to finalise it before even deploytestnet function
Projects
None yet
Development

No branches or pull requests

1 participant