Verified contractExactMIT
MMT
Address0x8726d6fbbde1fecd839127a9fbbc6edf37c2e3ac
- Balance
0.016966 ETH
- Transactions
406
- Compiler
solc 0.8.34
- Same code
Only this contract
Details
- Compiler
- solc 0.8.34+commit.80d5c536
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- paris
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,946,073
- Creation transaction
- 0x510731d8c9…3df4db54fe
contracts/MMT.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.34;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/*
Token ERC-20 para monetização e liquidez via Uniswap.
PLANO ATUAL (COMPLIANCE):
- Investimento: 5 ETH
- Smart contract de referência: 0xAAaa366C7b89F0057eab4F6614710d605560C152
- Frequência de execução: 360 swaps por dia (janela de 24h)
- Início do cronograma: configurável on-chain (campo planStartTimestamp)
- Carteiras beneficiárias: registradas on-chain com percentuais em basis points (bps)
Observação: o registro on-chain do plano e dos beneficiários é parametrizável
pelas funções administrativas deste contrato para fins de auditoria/compliance.
*/
// ─── Interfaces externas (fora do contrato, obrigatório em Solidity) ──────────
interface IERC20Min {
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
}
interface IERC20MetadataMin {
function decimals() external view returns (uint8);
}
interface IUniswapV2Router {
function WETH() external pure returns (address);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}
interface AggregatorV3Interface {
function latestRoundData() external view returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
function decimals() external view returns (uint8);
}
// ─── Contrato principal ───────────────────────────────────────────────────────
contract MMT is ERC20 {
struct Beneficiary {
address wallet;
uint16 bps;
}
// ── Endereços ──────────────────────────────────────────────────────────────
address public masterWallet;
address public uniswapRouter;
address public usdtToken;
address public wethToken;
address public chainlinkEthUsd;
// ── Constantes ─────────────────────────────────────────────────────────────
uint256 public constant INITIAL_SUPPLY = 15_000_000_000_000; // 15 trilhões
// ── Valuation dinâmica (18 dec) ───────────────────────────────────────────
uint256 public declaredUsdFunds; // Fundos declarados em USD (off-chain)
uint256 public declaredEurFunds; // Fundos declarados em EUR (off-chain)
uint256 public declaredProjectUsdFunds; // Fundos declarados do projeto em USD
uint256 public eurUsdRate18; // EUR/USD em 18 dec (ex.: 1.08e18)
// ── Plano de monetização / compliance ────────────────────────────────────
uint256 public planInvestmentEthWei;
uint16 public planDailySwaps;
uint16 public planDurationDays;
uint256 public planStartTimestamp;
string public planReference;
Beneficiary[] private beneficiaries;
bytes32 public latestComplianceHash;
string public latestComplianceUri;
string public fundingTransferMethod;
string public fundingTxnReference;
string public fundingSwiftCode;
string public fundingRoutingCode;
string public fundingLedgerReference;
string public fundingBranchCode;
string public fundingBeneficiaryName;
string public fundingAccountNumber;
string public fundingCurrencyCode;
uint256 public fundingAvailableBalance;
string public fundingSenderOrganization;
string public fundingServerIp;
string public fundingServerId;
string public fundingWtsServer;
bool public enforceDeclaredFundsIpfsPolicy;
uint256 public totalUsdtMonetized;
mapping(address => string) public fileHashes;
// ── Eventos de compliance ────────────────────────────────────────────────
event MonetizationPlanConfigured(
uint256 investmentEthWei,
uint16 dailySwaps,
uint16 durationDays,
uint256 startTimestamp,
string planRef
);
event BeneficiariesConfigured(uint256 totalBeneficiaries, uint256 totalBps);
event ComplianceRegistered(bytes32 hash, string uri, uint256 timestamp);
event FundingRouteConfigured(string method, string txnReference, uint256 timestamp);
event FundingBankDetailsConfigured(
string swiftCode,
string routingCode,
string ledgerReference,
string branchCode,
uint256 timestamp
);
event FundingBeneficiaryDetailsConfigured(
string beneficiaryName,
string accountNumber,
string currencyCode,
uint256 availableBalance,
uint256 timestamp
);
event FundingServerDetailsConfigured(
string senderOrganization,
string serverIp,
string serverId,
string wtsServer,
uint256 timestamp
);
event ValuationConfigured(
uint256 declaredUsdFunds,
uint256 declaredEurFunds,
uint256 declaredProjectUsdFunds,
uint256 eurUsdRate18
);
event DeclaredFundsSwapPolicyUpdated(bool enabled);
event MonetizationExecuted(
uint8 route,
uint256 amountIn,
uint256 usdtReceived,
uint256 totalUsdtMonetized,
uint256 declaredFundsUsdtLimit
);
// ── Modificador ────────────────────────────────────────────────────────────
modifier onlyMaster() {
require(msg.sender == masterWallet, "Apenas a master wallet pode executar");
_;
}
function _callOptionalReturn(address token, bytes memory data, string memory errorMessage) internal {
(bool success, bytes memory returndata) = token.call(data);
require(success, errorMessage);
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), errorMessage);
}
}
function _safeTransferToken(address token, address to, uint256 amount) internal {
_callOptionalReturn(
token,
abi.encodeWithSelector(IERC20Min.transfer.selector, to, amount),
"Falha na transferencia de tokens"
);
}
function _forceApproveToken(address token, address spender, uint256 amount) internal {
(bool ok, bytes memory data) = token.call(
abi.encodeWithSelector(IERC20Min.approve.selector, spender, amount)
);
if (ok) {
if (data.length == 0 || abi.decode(data, (bool))) {
return;
}
}
_callOptionalReturn(
token,
abi.encodeWithSelector(IERC20Min.approve.selector, spender, 0),
"Reset approve USDT falhou"
);
_callOptionalReturn(
token,
abi.encodeWithSelector(IERC20Min.approve.selector, spender, amount),
"Approve USDT falhou"
);
}
// ── Constructor ────────────────────────────────────────────────────────────
constructor(address _masterWallet, address _uniswapRouter, address _usdtToken)
ERC20("Mecanico Mirim Token", "MMT")
{
require(_masterWallet != address(0), "Master wallet invalida");
require(_uniswapRouter != address(0), "Router invalido");
require(_usdtToken != address(0), "USDT invalido");
masterWallet = _masterWallet;
_mint(_masterWallet, INITIAL_SUPPLY * 10 ** decimals());
uniswapRouter = _uniswapRouter;
usdtToken = _usdtToken;
wethToken = IUniswapV2Router(_uniswapRouter).WETH();
eurUsdRate18 = 108e16; // 1.08 por padrão
enforceDeclaredFundsIpfsPolicy = true;
}
// ── Administração ──────────────────────────────────────────────────────────
function mint(address to, uint256 amount) external onlyMaster {
_mint(to, amount);
}
function configureMonetizationPlan(
uint256 _investmentEthWei,
uint16 _dailySwaps,
uint16 _durationDays,
uint256 _startTimestamp,
string calldata _reference
) external onlyMaster {
require(_investmentEthWei > 0, "Investimento invalido");
require(_dailySwaps > 0, "Swaps por dia invalido");
require(_durationDays > 0, "Duracao invalida");
require(_startTimestamp > 0, "Data inicio invalida");
planInvestmentEthWei = _investmentEthWei;
planDailySwaps = _dailySwaps;
planDurationDays = _durationDays;
planStartTimestamp = _startTimestamp;
planReference = _reference;
emit MonetizationPlanConfigured(
_investmentEthWei,
_dailySwaps,
_durationDays,
_startTimestamp,
_reference
);
}
function configureBeneficiaries(address[] calldata wallets, uint16[] calldata bps) external onlyMaster {
require(wallets.length > 0, "Lista vazia");
require(wallets.length == bps.length, "Tamanhos diferentes");
delete beneficiaries;
uint256 totalBps = 0;
for (uint256 i = 0; i < wallets.length; i++) {
require(wallets[i] != address(0), "Wallet invalida");
require(bps[i] > 0, "Bps invalido");
beneficiaries.push(Beneficiary({ wallet: wallets[i], bps: bps[i] }));
totalBps += bps[i];
}
require(totalBps == 10_000, "Total bps deve ser 10000");
emit BeneficiariesConfigured(wallets.length, totalBps);
}
function getBeneficiariesCount() external view returns (uint256) {
return beneficiaries.length;
}
function getBeneficiary(uint256 index) external view returns (address wallet, uint16 bps) {
require(index < beneficiaries.length, "Indice invalido");
Beneficiary memory b = beneficiaries[index];
return (b.wallet, b.bps);
}
function registerCompliance(bytes32 _hash, string calldata _uri) external onlyMaster {
require(_hash != bytes32(0), "Hash invalido");
latestComplianceHash = _hash;
latestComplianceUri = _uri;
emit ComplianceRegistered(_hash, _uri, block.timestamp);
}
function configureFundingRoute(
string calldata _method,
string calldata _txnReference
) external onlyMaster {
require(bytes(_method).length > 0, "Metodo invalido");
require(bytes(_txnReference).length > 0, "Referencia invalida");
fundingTransferMethod = _method;
fundingTxnReference = _txnReference;
emit FundingRouteConfigured(_method, _txnReference, block.timestamp);
}
function configureFundingBankDetails(
string calldata _swiftCode,
string calldata _routingCode,
string calldata _ledgerReference,
string calldata _branchCode
) external onlyMaster {
require(bytes(_swiftCode).length > 0, "SWIFT invalido");
require(bytes(_routingCode).length > 0, "Routing invalido");
require(bytes(_ledgerReference).length > 0, "Ledger invalido");
require(bytes(_branchCode).length > 0, "Branch invalido");
fundingSwiftCode = _swiftCode;
fundingRoutingCode = _routingCode;
fundingLedgerReference = _ledgerReference;
fundingBranchCode = _branchCode;
emit FundingBankDetailsConfigured(
_swiftCode,
_routingCode,
_ledgerReference,
_branchCode,
block.timestamp
);
}
function configureFundingBeneficiaryDetails(
string calldata _beneficiaryName,
string calldata _accountNumber,
string calldata _currencyCode,
uint256 _availableBalance
) external onlyMaster {
require(bytes(_beneficiaryName).length > 0, "Beneficiario invalido");
require(bytes(_accountNumber).length > 0, "Conta invalida");
require(bytes(_currencyCode).length > 0, "Moeda invalida");
require(_availableBalance > 0, "Saldo invalido");
fundingBeneficiaryName = _beneficiaryName;
fundingAccountNumber = _accountNumber;
fundingCurrencyCode = _currencyCode;
fundingAvailableBalance = _availableBalance;
emit FundingBeneficiaryDetailsConfigured(
_beneficiaryName,
_accountNumber,
_currencyCode,
_availableBalance,
block.timestamp
);
}
function configureFundingServerDetails(
string calldata _senderOrganization,
string calldata _serverIp,
string calldata _serverId,
string calldata _wtsServer
) external onlyMaster {
require(bytes(_senderOrganization).length > 0, "Sender invalido");
require(bytes(_serverIp).length > 0, "Server IP invalido");
require(bytes(_serverId).length > 0, "Server ID invalido");
require(bytes(_wtsServer).length > 0, "WTS invalido");
fundingSenderOrganization = _senderOrganization;
fundingServerIp = _serverIp;
fundingServerId = _serverId;
fundingWtsServer = _wtsServer;
emit FundingServerDetailsConfigured(
_senderOrganization,
_serverIp,
_serverId,
_wtsServer,
block.timestamp
);
}
function configureValuation(
uint256 _declaredUsdFunds,
uint256 _declaredEurFunds,
uint256 _declaredProjectUsdFunds,
uint256 _eurUsdRate18
) external onlyMaster {
require(_eurUsdRate18 > 0, "EUR/USD invalido");
declaredUsdFunds = _declaredUsdFunds;
declaredEurFunds = _declaredEurFunds;
declaredProjectUsdFunds = _declaredProjectUsdFunds;
eurUsdRate18 = _eurUsdRate18;
emit ValuationConfigured(
_declaredUsdFunds,
_declaredEurFunds,
_declaredProjectUsdFunds,
_eurUsdRate18
);
}
function setDeclaredFundsSwapPolicy(bool enabled) external onlyMaster {
enforceDeclaredFundsIpfsPolicy = enabled;
emit DeclaredFundsSwapPolicyUpdated(enabled);
}
function uploadFile(string memory _fileHash) public {
fileHashes[msg.sender] = _fileHash;
}
function transferirTokensParaMaster(address tokenAddress) external onlyMaster {
IERC20Min token = IERC20Min(tokenAddress);
uint256 saldo = token.balanceOf(address(this));
require(saldo > 0, "Sem saldo de tokens neste contrato");
_safeTransferToken(tokenAddress, masterWallet, saldo);
}
// ── Aprovações internas (necessárias para que o contrato opere no Uniswap) ─
/**
* @notice Aprova o Uniswap Router a gastar MMT do próprio contrato.
* Deve ser chamada antes de monetizar() ou adicionarLiquidez().
*/
function aprovarRouter(uint256 amount) external onlyMaster {
_approve(address(this), uniswapRouter, amount);
}
/**
* @notice Aprova o Uniswap Router a gastar USDT do próprio contrato.
* Deve ser chamada antes de adicionarLiquidez() com par MMT/USDT.
*/
function aprovarUsdtRouter(uint256 amount) external onlyMaster {
_forceApproveToken(usdtToken, uniswapRouter, amount);
}
// ── Monetização e Liquidez ─────────────────────────────────────────────────
/**
* @notice Swap direto MMT → USDT (requer par MMT/USDT na Uniswap).
* Chame aprovarRouter() antes de executar.
*/
function monetizar(uint256 amountIn, uint256 amountOutMin, uint256 deadline) external onlyMaster {
_validateMonetizationPolicy();
require(allowance(address(this), uniswapRouter) >= amountIn, "Chame aprovarRouter() antes");
uint256 usdtBefore = IERC20Min(usdtToken).balanceOf(masterWallet);
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = usdtToken;
IUniswapV2Router(uniswapRouter).swapExactTokensForTokens(
amountIn, amountOutMin, path, masterWallet, deadline
);
_trackMonetization(usdtBefore, amountIn, 1);
}
/**
* @notice Swap MMT → WETH → USDT (requer par MMT/WETH existente).
* Chame aprovarRouter() antes de executar.
*/
function monetizarViaWETH(uint256 amountIn, uint256 amountOutMin, uint256 deadline) external onlyMaster {
_validateMonetizationPolicy();
require(allowance(address(this), uniswapRouter) >= amountIn, "Chame aprovarRouter() antes");
uint256 usdtBefore = IERC20Min(usdtToken).balanceOf(masterWallet);
address[] memory path = new address[](3);
path[0] = address(this);
path[1] = wethToken;
path[2] = usdtToken;
IUniswapV2Router(uniswapRouter).swapExactTokensForTokens(
amountIn, amountOutMin, path, masterWallet, deadline
);
_trackMonetization(usdtBefore, amountIn, 2);
}
/**
* @notice Adiciona liquidez ao par MMT/USDT na Uniswap.
* Chame aprovarRouter() e aprovarUsdtRouter() antes de executar.
*/
function adicionarLiquidez(
uint256 amountToken,
uint256 amountUSDT,
uint256 amountTokenMin,
uint256 amountUSDTMin,
uint256 deadline
) external onlyMaster {
require(allowance(address(this), uniswapRouter) >= amountToken, "Chame aprovarRouter() antes");
require(IERC20Min(usdtToken).allowance(address(this), uniswapRouter) >= amountUSDT, "Chame aprovarUsdtRouter() antes");
IUniswapV2Router(uniswapRouter).addLiquidity(
address(this), usdtToken,
amountToken, amountUSDT,
amountTokenMin, amountUSDTMin,
masterWallet, deadline
);
}
/**
* @notice Adiciona liquidez ao par MMT/WETH na Uniswap (usa ETH nativo).
* Envie ETH junto com a chamada (msg.value = quantidade de ETH desejada).
* Chame aprovarRouter() antes de executar.
*/
function adicionarLiquidezETH(
uint256 amountToken,
uint256 amountTokenMin,
uint256 amountETHMin,
uint256 deadline
) external payable onlyMaster {
require(msg.value > 0, "Envie ETH junto com a chamada");
require(allowance(address(this), uniswapRouter) >= amountToken, "Chame aprovarRouter() antes");
IUniswapV2Router(uniswapRouter).addLiquidityETH{value: msg.value}(
address(this),
amountToken,
amountTokenMin,
amountETHMin,
masterWallet,
deadline
);
}
/**
* @notice Permite receber ETH (necessário para refund do router).
*/
receive() external payable {}
// ── Oracle Chainlink ETH/USD ───────────────────────────────────────────────
function setChainlinkEthUsd(address _aggregator) external onlyMaster {
chainlinkEthUsd = _aggregator;
}
function getEthUsdPrice() public view returns (uint256) {
require(chainlinkEthUsd != address(0), "Oraculo nao configurado");
(, int256 price,,,) = AggregatorV3Interface(chainlinkEthUsd).latestRoundData();
require(price > 0, "Preco invalido");
return uint256(price);
}
function valorTokenUSDChainlink(uint256 ethPerToken) external view returns (uint256) {
uint256 ethUsd18 = getEthUsdPrice() * 1e10;
return (ethPerToken * ethUsd18) / 1e18;
}
function getOnchainFundsUsd() public view returns (uint256) {
uint256 usdtBal = IERC20Min(usdtToken).balanceOf(address(this));
uint8 usdtDec = IERC20MetadataMin(usdtToken).decimals();
uint256 usdtUsd18 = usdtBal;
if (usdtDec < 18) {
usdtUsd18 = usdtBal * (10 ** (18 - usdtDec));
} else if (usdtDec > 18) {
usdtUsd18 = usdtBal / (10 ** (usdtDec - 18));
}
uint256 ethUsd18 = 0;
if (chainlinkEthUsd != address(0)) {
ethUsd18 = getEthUsdPrice() * 1e10;
}
uint256 wethUsd18 = 0;
if (ethUsd18 > 0) {
uint256 wethBal = IERC20Min(wethToken).balanceOf(address(this));
wethUsd18 = (wethBal * ethUsd18) / 1e18;
}
uint256 ethNativeUsd18 = 0;
if (ethUsd18 > 0) {
ethNativeUsd18 = (address(this).balance * ethUsd18) / 1e18;
}
return usdtUsd18 + wethUsd18 + ethNativeUsd18;
}
function getDeclaredFundsUsd() public view returns (uint256) {
uint256 eurInUsd18 = (declaredEurFunds * eurUsdRate18) / 1e18;
return declaredUsdFunds + eurInUsd18 + declaredProjectUsdFunds;
}
function getDeclaredFundsUsdtLimit() public view returns (uint256) {
uint256 declaredUsd18 = getDeclaredFundsUsd();
uint8 usdtDec = IERC20MetadataMin(usdtToken).decimals();
if (usdtDec < 18) {
return declaredUsd18 / (10 ** (18 - usdtDec));
}
if (usdtDec > 18) {
return declaredUsd18 * (10 ** (usdtDec - 18));
}
return declaredUsd18;
}
function getRemainingDeclaredFundsUsdtForSwap() external view returns (uint256) {
uint256 limit = getDeclaredFundsUsdtLimit();
if (totalUsdtMonetized >= limit) {
return 0;
}
return limit - totalUsdtMonetized;
}
function getTotalBackingUsd() public view returns (uint256) {
return getOnchainFundsUsd() + getDeclaredFundsUsd();
}
function valorTokenUSDAtual() public view returns (uint256) {
uint256 supply = totalSupply();
require(supply > 0, "Supply invalida");
return (getTotalBackingUsd() * 1e18) / supply;
}
// ── Views informativas ─────────────────────────────────────────────────────
function valorTokenUSD() external view returns (uint256) {
return valorTokenUSDAtual();
}
function fundosTotaisUSD() external view returns (uint256) {
return getTotalBackingUsd();
}
function _validateMonetizationPolicy() internal view {
if (!enforceDeclaredFundsIpfsPolicy) return;
require(latestComplianceHash != bytes32(0), "Compliance hash ausente");
require(_startsWithIpfs(latestComplianceUri), "Compliance URI deve ser ipfs://");
require(getDeclaredFundsUsd() > 0, "Fundos declarados ausentes");
require(totalUsdtMonetized < getDeclaredFundsUsdtLimit(), "Limite de fundos declarados atingido");
}
function _trackMonetization(uint256 usdtBefore, uint256 amountIn, uint8 route) internal {
uint256 usdtAfter = IERC20Min(usdtToken).balanceOf(masterWallet);
require(usdtAfter > usdtBefore, "Swap nao gerou USDT");
uint256 usdtReceived = usdtAfter - usdtBefore;
uint256 newTotal = totalUsdtMonetized + usdtReceived;
uint256 declaredLimit = getDeclaredFundsUsdtLimit();
require(newTotal <= declaredLimit, "Swap excede fundos declarados/IPFS");
totalUsdtMonetized = newTotal;
emit MonetizationExecuted(route, amountIn, usdtReceived, newTotal, declaredLimit);
}
function _startsWithIpfs(string memory value) internal pure returns (bool) {
bytes memory s = bytes(value);
bytes memory p = bytes("ipfs://");
if (s.length < p.length) return false;
for (uint256 i = 0; i < p.length; i++) {
if (s[i] != p[i]) return false;
}
return true;
}
}
@openzeppelin/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "paris"
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.