Contract Source Code (Solidity Standard Json-Input format)
File 1 of 1 : TUSD.sol
// SPDX-License-Identifier: Unlicensed
pragma solidity 0.8.10;
/// @title Ownable - Basic ownership control mechanism
/// @notice Provides a modifier to restrict function access to the contract owner
contract Ownable {
/// @notice The address of the contract owner
address public owner;
/// @notice Restricts function access to only the current owner
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/// @notice Transfers ownership to a new address
/// @param newOwner The address to be assigned as the new owner
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "New owner is zero address");
owner = newOwner;
}
}
/// @title ITBC20 - Interface for ERC-20 like token
/// @notice Describes the standard ERC-20 token functions and events
interface ITBC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/// @notice Emitted when tokens are transferred between addresses
event Transfer(address indexed from, address indexed to, uint256 value);
/// @notice Emitted when an approval is made for a spender
event Approval(address indexed owner, address indexed spender, uint256 value);
}
/// @title TBC20Basic - A basic TBC-20 implementation with minting and ownership
/// @notice Implements the ITBC20 interface with additional mint functionality
contract TBC20Basic is ITBC20, Ownable {
/// @notice Tracks the current total circulating supply
uint256 circulatingSupply;
/// @notice Mapping of user balances
mapping(address => uint256) balances;
/// @notice Nested mapping to track allowances
mapping(address => mapping (address => uint256)) allowed;
/// @notice Returns the total number of tokens in circulation
/// @return The circulating token supply
function totalSupply() public override view returns (uint256) {
return circulatingSupply ;
}
/// @notice Gets the token balance of a specific address
/// @param tokenOwner The address to query
/// @return The balance of the queried address
function balanceOf(address tokenOwner) public override view returns (uint256) {
return balances[tokenOwner];
}
/// @notice Transfers tokens to a specified address
/// @param receiver The address to receive the tokens
/// @param numTokens The number of tokens to transfer
/// @return True if the transfer was successful
function transfer(address receiver, uint256 numTokens) public override returns (bool) {
require(numTokens <= balances[msg.sender], "Transfer amount exceeds balance");
require(receiver != address(0), "Transfer from the zero address");
balances[address(msg.sender)] -= numTokens;
balances[address(receiver)] += numTokens;
emit Transfer(address(msg.sender), address(receiver), numTokens);
return true;
}
/// @notice Approves a spender to transfer tokens on your behalf
/// @param spender The address authorized to spend
/// @param numTokens The number of tokens to approve
/// @return True if the approval was successful
function approve(address spender, uint256 numTokens) public override returns (bool) {
allowed[address(msg.sender)][address(spender)] = numTokens;
emit Approval(address(msg.sender), address(spender), numTokens);
return true;
}
/// @notice Returns the remaining number of tokens that a spender can spend
/// @param owner The address which owns the tokens
/// @param spender The address which will spend the tokens
/// @return The remaining allowance
function allowance(address owner, address spender) public override view returns (uint) {
return allowed[address(owner)][address(spender)];
}
/// @notice Transfers tokens on behalf of another address
/// @param sender The address to send tokens from
/// @param receiver The address to transfer tokens to
/// @param numTokens The number of tokens to transfer
/// @return True if the transfer was successful
function transferFrom(address sender, address receiver, uint256 numTokens) public override returns (bool) {
require(numTokens <= balances[sender], "Transfer amount exceeds balance");
require(numTokens <= allowed[sender][msg.sender], "Transfer amount exceeds allowance");
require(receiver != address(0), "Transfer to the zero address");
balances[address(sender)] -= numTokens;
balances[address(receiver)] += numTokens;
allowed[address(sender)][address(msg.sender)] -= numTokens;
emit Transfer(address(sender), address(receiver), numTokens);
return true;
}
/// @notice Mints new tokens to the owner's balance
/// @dev Can only be called by the contract owner
/// @param numTokens The number of tokens to mint
function mint(uint256 numTokens) public onlyOwner {
require(numTokens + circulatingSupply <= 2100000000 * 10**18, "Mint limit exceeds");
circulatingSupply += numTokens;
balances[address(msg.sender)] += numTokens;
emit Transfer(address(0), address(msg.sender), numTokens);
}
}
/// @title TUSD Token Contract
/// @notice TBC-20 compatible token with an initial supply and minting ability
contract TUSD is TBC20Basic {
/// @notice The name of the token
string public constant name = "Trust USD";
/// @notice The token symbol
string public constant symbol = "TUSD";
/// @notice Number of decimals used by the token
uint8 public constant decimals = 18;
/// @notice Initializes the token with a predefined supply assigned to the given receiver
/// @param receiver The address that receives the initial supply and becomes the owner
constructor(address receiver) {
require(receiver != address(0), "Receiver is zero address");
owner = address(receiver);
circulatingSupply = 210000000 * 10**18;
balances[address(receiver)] = circulatingSupply;
emit Transfer(address(0), address(receiver), circulatingSupply);
}
}