文件 1 的 8:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 8:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
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;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
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;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
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;
}
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;
}
_balances[to] += amount;
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
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;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
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;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
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);
}
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);
}
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
文件 3 的 8:FractonFFT.sol
pragma solidity ^0.8.9;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/utils/math/SafeMath.sol';
import '../interface/IFractonFFT.sol';
import '../interface/IFractonTokenFactory.sol';
contract FractonFFT is ERC20, IFractonFFT {
using SafeMath for uint256;
mapping(address => bool) private _isExcludedFromFee;
address public _factory;
uint256 public vaultPercent = 20;
uint256 public pfVaultPercent = 0;
modifier onlyOwner() {
address owner = IFractonTokenFactory(_factory).getowner();
require(msg.sender == owner, 'Fracton: caller is not the owner');
_;
}
modifier onlyDAO() {
address dao = IFractonTokenFactory(_factory).getDAOAddress();
require(msg.sender == dao, 'Fracton: caller is not Fracton DAO');
_;
}
modifier onlySwap() {
address dao = IFractonTokenFactory(_factory).getSwapAddress();
require(msg.sender == dao, 'Fracton: caller is not swap');
_;
}
constructor(string memory name_, string memory symbol_)
ERC20(name_, symbol_)
{
_factory = msg.sender;
_isExcludedFromFee[_factory] = true;
_isExcludedFromFee[IFractonTokenFactory(_factory).getSwapAddress()] = true;
_isExcludedFromFee[
IFractonTokenFactory(_factory).getPoolFundingVaultAddress()
] = true;
_isExcludedFromFee[IFractonTokenFactory(_factory).getVaultAddress()] = true;
_isExcludedFromFee[address(this)] = true;
}
function swapmint(uint256 amount, address to)
external
virtual
override
onlySwap
returns (bool)
{
_mint(to, amount);
return true;
}
function ceil(uint256 a, uint256 m) internal pure returns (uint256) {
uint256 c = a.add(m);
uint256 d = c.sub(1);
return d.div(m).mul(m);
}
function cut(uint256 value, uint256 percent) public pure returns (uint256) {
if (percent == 0) {
return 0;
} else {
uint256 roundValue = ceil(value, percent);
uint256 cutValue = roundValue.mul(percent).div(10000);
return cutValue;
}
}
function transfer(address to, uint256 value)
public
virtual
override(ERC20, IFractonFFT)
returns (bool)
{
address from = _msgSender();
require(value <= balanceOf(from), 'from balance insufficient');
if (isExcludedFromFee(from) || isExcludedFromFee(to)) {
_transfer(from, to, value);
} else {
uint256 vaultFee = cut(value, vaultPercent);
uint256 pfVaultFee = cut(value, pfVaultPercent);
uint256 tokensToTransfer = value.sub(vaultFee).sub(pfVaultFee);
_transfer(
from,
IFractonTokenFactory(_factory).getVaultAddress(),
vaultFee
);
_transfer(
from,
IFractonTokenFactory(_factory).getPoolFundingVaultAddress(),
pfVaultFee
);
_transfer(from, to, tokensToTransfer);
}
return true;
}
function multiTransfer(address[] memory receivers, uint256[] memory amounts)
public
virtual
override
{
for (uint256 i = 0; i < receivers.length; i++) {
transfer(receivers[i], amounts[i]);
}
}
function transferFrom(
address from,
address to,
uint256 value
) public virtual override(ERC20, IFractonFFT) returns (bool) {
address spender = _msgSender();
require(value <= balanceOf(from), 'from balance insufficient');
if (isExcludedFromFee(from) || isExcludedFromFee(to)) {
_spendAllowance(from, spender, value);
_transfer(from, to, value);
} else {
uint256 vaultFee = cut(value, vaultPercent);
uint256 pfVaultFee = cut(value, pfVaultPercent);
uint256 tokensToTransfer = value.sub(vaultFee).sub(pfVaultFee);
_spendAllowance(from, spender, value);
_transfer(
from,
IFractonTokenFactory(_factory).getVaultAddress(),
vaultFee
);
_transfer(
from,
IFractonTokenFactory(_factory).getPoolFundingVaultAddress(),
pfVaultFee
);
_transfer(from, to, tokensToTransfer);
}
return true;
}
function burnFrom(address from, uint256 value)
external
virtual
override
returns (bool)
{
address spender = _msgSender();
if (from != spender) {
_spendAllowance(from, spender, value);
}
_burn(from, value);
return true;
}
function excludeFromFee(address account) public onlyDAO returns (bool) {
_isExcludedFromFee[account] = true;
return true;
}
function batchExcludeFromFee(address[] memory accounts)
external
onlyDAO
returns (bool)
{
for (uint256 i = 0; i < accounts.length; i++) {
_isExcludedFromFee[accounts[i]] = true;
}
return true;
}
function includeInFee(address account) external onlyDAO returns (bool) {
_isExcludedFromFee[account] = false;
return true;
}
function updateFee(uint256 vaultPercent_, uint256 pfVaultPercent_)
external
override
onlyDAO
returns (bool)
{
vaultPercent = vaultPercent_;
pfVaultPercent = pfVaultPercent_;
emit SetPercent(vaultPercent_, pfVaultPercent_);
return true;
}
function isExcludedFromFee(address account)
public
view
virtual
override
returns (bool)
{
return _isExcludedFromFee[account];
}
}
文件 4 的 8:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 5 的 8:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 6 的 8:IFractonFFT.sol
pragma solidity ^0.8.9;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
interface IFractonFFT is IERC20 {
event SetPercent(uint256 vaultPercent, uint256 pfVaultPercent);
function swapmint(uint256 amount, address to) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function multiTransfer(address[] memory receivers, uint256[] memory amounts)
external;
function transferFrom(
address from,
address to,
uint256 value
) external returns (bool);
function burnFrom(address from, uint256 value) external returns (bool);
function isExcludedFromFee(address account) external view returns (bool);
function updateFee(uint256 vaultPercent_, uint256 pfVaultPercent_)
external
returns (bool);
}
文件 7 的 8:IFractonTokenFactory.sol
pragma solidity ^0.8.9;
interface IFractonTokenFactory {
function getowner() external view returns (address);
function getDAOAddress() external view returns (address);
function getVaultAddress() external view returns (address);
function getSwapAddress() external view returns (address);
function getPoolFundingVaultAddress() external view returns (address);
}
文件 8 的 8:SafeMath.sol
pragma solidity ^0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
{
"compilationTarget": {
"contracts/fundraising/FractonFFT.sol": "FractonFFT"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"vaultPercent","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pfVaultPercent","type":"uint256"}],"name":"SetPercent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"_factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"}],"name":"batchExcludeFromFee","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"burnFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"percent","type":"uint256"}],"name":"cut","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"excludeFromFee","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"includeInFee","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isExcludedFromFee","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"receivers","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"multiTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pfVaultPercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"swapmint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"vaultPercent_","type":"uint256"},{"internalType":"uint256","name":"pfVaultPercent_","type":"uint256"}],"name":"updateFee","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vaultPercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]