文件 1 的 7:DFBTCPoolsLPStakingPools.sol
pragma solidity =0.6.6;
pragma experimental ABIEncoderV2;
import './libraries/SafeMath.sol';
import './libraries/TransferHelper.sol';
import './interfaces/IERC20.sol';
import './interfaces/IUniswapV2Pair.sol';
import './libraries/UniswapV2Library.sol';
import './interfaces/IDFBTCPoolsLPStakingPools.sol';
contract DFBTCPoolsLPStakingPools is IDFBTCPoolsLPStakingPools {
using SafeMath for uint;
mapping(address=>mapping(uint=>uint)) public tokenTocycleToPools;
mapping(address=>uint) public tokenToDecimal;
address public owner;
address public uniswapLP;
address public aom = 0x060924FB947e37EEE230d0B1A71D9618aEc269fC;
uint private unlocked = 1;
modifier lock() {
require(unlocked == 1, 'dfbtc: LOCKED');
unlocked = 0;
_;
unlocked = 1;
}
constructor() public {
owner = msg.sender;
tokenTocycleToPools[0x060924FB947e37EEE230d0B1A71D9618aEc269fC][30] = 7600e18;
tokenTocycleToPools[0xdAC17F958D2ee523a2206206994597C13D831ec7][30] = 3420e18;
tokenTocycleToPools[0x060924FB947e37EEE230d0B1A71D9618aEc269fC][90] = 26600e18;
tokenTocycleToPools[0xdAC17F958D2ee523a2206206994597C13D831ec7][90] = 11970e18;
tokenTocycleToPools[0x060924FB947e37EEE230d0B1A71D9618aEc269fC][180] = 57000e18;
tokenTocycleToPools[0xdAC17F958D2ee523a2206206994597C13D831ec7][180] = 25650e18;
tokenTocycleToPools[0x060924FB947e37EEE230d0B1A71D9618aEc269fC][360] = 121600e18;
tokenTocycleToPools[0xdAC17F958D2ee523a2206206994597C13D831ec7][360] = 54720e18;
tokenTocycleToPools[0xB405652045933aFDCDC6FcBbFb4D0ecaF33C67f0][30] = 26980e18;
tokenTocycleToPools[0xB405652045933aFDCDC6FcBbFb4D0ecaF33C67f0][90] = 94430e18;
tokenTocycleToPools[0xB405652045933aFDCDC6FcBbFb4D0ecaF33C67f0][180] = 202350e18;
tokenTocycleToPools[0xB405652045933aFDCDC6FcBbFb4D0ecaF33C67f0][360] = 431680e18;
tokenToDecimal[0xB405652045933aFDCDC6FcBbFb4D0ecaF33C67f0] = 1;
tokenToDecimal[0x060924FB947e37EEE230d0B1A71D9618aEc269fC] = 1;
tokenToDecimal[0xdAC17F958D2ee523a2206206994597C13D831ec7] = 1;
}
modifier onlyOnwer {
require(owner == msg.sender, "dfbtc: The caller must be onwer!!!");
_;
}
modifier onlyOnwerOrLP {
require(owner == msg.sender || uniswapLP == msg.sender, "dfbtc: The caller must be onwer!!!");
_;
}
function setAOM(address newAom) public lock onlyOnwer {
aom = newAom;
}
function safeTransferAomToUser(address to, uint amount) external override lock onlyOnwerOrLP {
TransferHelper.safeTransfer(aom, to, amount);
}
function setTokenTocycleToPools(address tokenAddress, uint cycle, uint poolsAmount) public lock onlyOnwer {
tokenTocycleToPools[tokenAddress][cycle] = poolsAmount;
}
function setUniswapLP(address uniswapAddress) public lock onlyOnwer {
uniswapLP = uniswapAddress;
}
function setTokenToDecimal(address tokenAddress, uint decimalVal) public lock onlyOnwer {
tokenToDecimal[tokenAddress] = decimalVal;
}
function safeTransferToOtherPools(address tokenAddress, address toAdddress, uint transferValue) public lock onlyOnwer {
TransferHelper.safeTransfer(tokenAddress, toAdddress, transferValue);
}
function calEveryDayAom(address token, uint dayTotal, uint pledgeCycle, uint amount) external override view returns(uint){
return tokenTocycleToPools[token][pledgeCycle].mul(amount.mul(1000000000000000000).div(dayTotal)).div(pledgeCycle).mul(tokenToDecimal[token]).div(1000000000000000000);
}
}
文件 2 的 7:IDFBTCPoolsLPStakingPools.sol
pragma solidity =0.6.6;
interface IDFBTCPoolsLPStakingPools {
function calEveryDayAom(address token, uint dayTotal, uint pledgeCycle, uint amount) external view returns(uint);
function safeTransferAomToUser(address to, uint amount) external;
}
文件 3 的 7:IERC20.sol
pragma solidity >=0.5.0;
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function mint(address _to, uint256 _amount) external returns (bool);
function burn(uint value) external;
}
文件 4 的 7:IUniswapV2Pair.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
文件 5 的 7:SafeMath.sol
pragma solidity =0.6.6;
library SafeMath {
function mul(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
if (_a == 0) {
return 0;
}
c = _a * _b;
require(c / _a == _b, "mul error!!");
return c;
}
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
return _a / _b;
}
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b <= _a, "sub error!!");
return _a - _b;
}
function add(uint256 _a, uint256 _b) internal pure returns (uint256 c) {
c = _a + _b;
require(c >= _a, "add error!!");
return c;
}
}
文件 6 的 7:TransferHelper.sol
pragma solidity >=0.6.6;
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
}
文件 7 的 7:UniswapV2Library.sol
pragma solidity >=0.5.0;
import '../interfaces/IUniswapV2Pair.sol';
import "./SafeMath.sol";
library UniswapV2Library {
using SafeMath for uint;
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
))));
}
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
}
{
"compilationTarget": {
"DFBTCPoolsLPStakingPools.sol": "DFBTCPoolsLPStakingPools"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"aom","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"dayTotal","type":"uint256"},{"internalType":"uint256","name":"pledgeCycle","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"calEveryDayAom","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"safeTransferAomToUser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"toAdddress","type":"address"},{"internalType":"uint256","name":"transferValue","type":"uint256"}],"name":"safeTransferToOtherPools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAom","type":"address"}],"name":"setAOM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"decimalVal","type":"uint256"}],"name":"setTokenToDecimal","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"cycle","type":"uint256"},{"internalType":"uint256","name":"poolsAmount","type":"uint256"}],"name":"setTokenTocycleToPools","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"uniswapAddress","type":"address"}],"name":"setUniswapLP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tokenToDecimal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokenTocycleToPools","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"uniswapLP","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]