Verified contractExact
MFS
Address0x361d145aecbb68c659493c8dfd2d519858d0f062
- Balance
0 ETH
- Transactions
20
- Compiler
solc 0.6.12
- Same code
Only this contract
Details
- Compiler
- solc 0.6.12+commit.27d51765
- Language
- solidity
- Optimization
- No
- EVM version
- istanbul
- License
- Not stated
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 12,002,888
- Creation transaction
- 0x4ab204b8df…7e0e5a36da
browser/MFS.sol
pragma solidity ^0.6.6;
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
* 返回存在的令牌数量。
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
* 返回`account`拥有的令牌数量。
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
* 将“数量”令牌从呼叫者的帐户移至“收件人”。
* Returns a boolean value indicating whether the operation succeeded.
* 返回一个布尔值,该值指示操作是否成功。
* Emits a {Transfer} event.
* 发出{Transfer}事件。
*/
function transfer(address recipient, 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.
* 返回将允许`spender`通过{transferFrom}代表`owner`使用的令牌剩余数量。默认为零。
* This value changes when {approve} or {transferFrom} are called.
* 调用{approve}或{transferFrom}时,此值会更改。
*/
function allowance(address owner, address spender)
external
view
returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
* 将“金额”设置为对调用者令牌的“ spender”配额。
* 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.
* 发出{Approval}事件
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` 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.
* 发出{Transfer}事件。
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @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.
* 当通过调用{approve}设置“ spender”对“ owner”的许可时发出。 “价值”是新的免税额。
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
contract Owned {
address public owner;
address public newOwner;
event OwnershipTransferred(address indexed _from, address indexed _to);
constructor() public {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function transferOwnership(address _newOwner) public onlyOwner {
newOwner = _newOwner;
}
function acceptOwnership() public {
require(msg.sender == newOwner);
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
newOwner = address(0);
}
}
contract MFS is Owned {
//存款事件 传入(用户地址,存款数量,存款时间)
event BANK_SAVINGS(address indexed userAddress, uint quantity, uint blockTime);
//兑换事件 传入(用户地址,存款数量,兑换数量,兑换时间)
event EXCHANGE(address indexed userAddress, uint quantity, uint exchangeCount, uint blockTime);
//防溢出计算
using SafeMath for uint;
//mfs地址(存入代币地址)
IERC20 private mfsToken;
//vcmfs地址(兑换出代币地址)
IERC20 private vcmfsToken;
//mfs总数
uint private mfsCount;
//vcmfs总数
uint private vcmfsCount;
//存入上限
uint private upper_Limit;
//兑换率(3mfs:1vcmfs)
uint private exchange;
//判断
bool private res;
//是否超过上限
modifier counter{
require(mfsCount <= upper_Limit, 'MFS:Over limit');
_;
}
constructor(address mfsAddress, address vcmfsAddress) public {
//初始化mfs地址
mfsToken = IERC20(mfsAddress);
//初始化vcmfs地址
vcmfsToken = IERC20(vcmfsAddress);
//初始mfs总数
mfsCount = 0;
//初始vcmfs总数
vcmfsCount = 0;
//初始可存入上限 6000*1e18
upper_Limit = 6000000001200000000000;
//初始兑换率 3
exchange = 3000000000000000000;
//交易是否成功初始为false
res = false;
}
/*
存款
传入 数量
返回 是否成功
*/
function deposit(uint mfsQuantity) public counter returns (bool){
(uint _value,uint _vcmfs) = calculation(mfsQuantity);
require((((mfsQuantity.mul(10)).div(exchange.div(1e18))).div(10))<_vcmfs,"MFS:Incoming MFS is greater than VCMFS balance");
res = false;
res = mfsToken.transferFrom(msg.sender, address(this), mfsQuantity);
if (res == false) {
revert();
}
mfsCount = mfsCount.add(mfsQuantity);
emit BANK_SAVINGS(msg.sender, mfsQuantity, block.timestamp);
reward(mfsQuantity,_value);
return true;
}
/*
奖励给用户
传入 奖励数量
*/
function reward(uint mfsQuantity, uint vcmfsQuantity) private returns (bool){
res = false;
res = vcmfsToken.transfer(msg.sender, vcmfsQuantity);
if (res == false) {
revert();
}
vcmfsCount = vcmfsCount.sub(vcmfsQuantity);
emit EXCHANGE(msg.sender, mfsQuantity, vcmfsQuantity, block.timestamp);
return true;
}
/*
计算
传入 数量
返回 可换出数量
*/
function calculation(uint _quantity) private view returns (uint value,uint _vcmfs){
value = (_quantity.mul(10)).div(exchange.div(1e18));
return (value.div(10),vcmfsCount);
}
/*------------------------- 设置类 -----------------------------*/
/*
转入vcmfs
传入 数量
返回 转入是否成功
*/
function depositVcmfs(uint quantity) public onlyOwner returns (bool){
res = false;
res = vcmfsToken.transferFrom(msg.sender, address(this), quantity);
if (res == false) {
revert();
}
vcmfsCount = vcmfsCount.add(quantity);
return true;
}
/*
取出ERC20
传入 数量
返回 取出是否成功
*/
function takeoutMfs(address tokens,uint quantity) public onlyOwner returns (bool){
res = false;
res = IERC20(tokens).transfer(msg.sender, quantity);
if (res == false) {
revert();
}
mfsCount = mfsCount.sub(quantity);
return true;
}
/*
修改存入代币地址
传入 新代币地址
*/
function setMfsTokenAddr(address mfsTokenAddr, address vcmfsTokenAddr) public onlyOwner {
mfsToken = IERC20(mfsTokenAddr);
vcmfsToken = IERC20(vcmfsTokenAddr);
}
/*
修改上限
传入 十进制数量
*/
function setUpperLimit(uint quantity) public onlyOwner {
upper_Limit = quantity.mul(1e18);
}
/*
修改兑换率
传入 十进制兑换率
*/
function setExchange(uint _exchange) public onlyOwner {
exchange = _exchange.mul(1e18);
}
/*------------------------- 查看类 -----------------------------*/
/*
查看
返回
mfs地址(存入代币地址)
vcmfs地址(兑换出代币地址)
mfs总数
vcmfs总数
存入上限
兑换率(3mfs:1vcmfs)
*/
function getGameInfo() public view returns (address, address, uint, uint, uint, uint){
return(
address(mfsToken),
address(vcmfsToken),
mfsCount,
vcmfsCount,
upper_Limit,
exchange);
}
}Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": false
},
"evmVersion": "istanbul",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.