编译器
0.5.17+commit.d19bba13
文件 1 的 13:ABDK.sol
pragma solidity ^0.5.0 || ^0.6.0;
library ABDKMath64x64 {
int128 private constant MIN_64x64 = -0x80000000000000000000000000000000;
int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
function toInt (int128 x) internal pure returns (int64) {
return int64 (x >> 64);
}
function to128x128 (int128 x) internal pure returns (int256) {
return int256 (x) << 64;
}
function add (int128 x, int128 y) internal pure returns (int128) {
int256 result = int256(x) + y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
function sub (int128 x, int128 y) internal pure returns (int128) {
int256 result = int256(x) - y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
function mul (int128 x, int128 y) internal pure returns (int128) {
int256 result = int256(x) * y >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
function muli (int128 x, int256 y) internal pure returns (int256) {
if (x == MIN_64x64) {
require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF &&
y <= 0x1000000000000000000000000000000000000000000000000);
return -y << 63;
} else {
bool negativeResult = false;
if (x < 0) {
x = -x;
negativeResult = true;
}
if (y < 0) {
y = -y;
negativeResult = !negativeResult;
}
uint256 absoluteResult = mulu (x, uint256 (y));
if (negativeResult) {
require (absoluteResult <=
0x8000000000000000000000000000000000000000000000000000000000000000);
return -int256 (absoluteResult);
} else {
require (absoluteResult <=
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int256 (absoluteResult);
}
}
}
function mulu (int128 x, uint256 y) internal pure returns (uint256) {
if (y == 0) return 0;
require (x >= 0);
uint256 lo = (uint256 (x) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64;
uint256 hi = uint256 (x) * (y >> 128);
require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
hi <<= 64;
require (hi <=
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo);
return hi + lo;
}
function div (int128 x, int128 y) internal pure returns (int128) {
require (y != 0);
int256 result = (int256 (x) << 64) / y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
function divi (int256 x, int256 y) internal pure returns (int128) {
require (y != 0);
bool negativeResult = false;
if (x < 0) {
x = -x;
negativeResult = true;
}
if (y < 0) {
y = -y;
negativeResult = !negativeResult;
}
uint128 absoluteResult = divuu (uint256 (x), uint256 (y));
if (negativeResult) {
require (absoluteResult <= 0x80000000000000000000000000000000);
return -int128 (absoluteResult);
} else {
require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int128 (absoluteResult);
}
}
function divu (uint256 x, uint256 y) internal pure returns (int128) {
require (y != 0);
uint128 result = divuu (x, y);
require (result <= uint128 (MAX_64x64));
return int128 (result);
}
function neg (int128 x) internal pure returns (int128) {
require (x != MIN_64x64);
return -x;
}
function abs (int128 x) internal pure returns (int128) {
require (x != MIN_64x64);
return x < 0 ? -x : x;
}
function exp_2 (int128 x) internal pure returns (int128) {
require (x < 0x400000000000000000);
if (x < -0x400000000000000000) return 0;
uint256 result = 0x80000000000000000000000000000000;
if (x & 0x8000000000000000 > 0)
result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128;
if (x & 0x4000000000000000 > 0)
result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128;
if (x & 0x2000000000000000 > 0)
result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128;
if (x & 0x1000000000000000 > 0)
result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128;
if (x & 0x800000000000000 > 0)
result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128;
if (x & 0x400000000000000 > 0)
result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128;
if (x & 0x200000000000000 > 0)
result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128;
if (x & 0x100000000000000 > 0)
result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128;
if (x & 0x80000000000000 > 0)
result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128;
if (x & 0x40000000000000 > 0)
result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128;
if (x & 0x20000000000000 > 0)
result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128;
if (x & 0x10000000000000 > 0)
result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128;
if (x & 0x8000000000000 > 0)
result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128;
if (x & 0x4000000000000 > 0)
result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128;
if (x & 0x2000000000000 > 0)
result = result * 0x1000162E525EE054754457D5995292026 >> 128;
if (x & 0x1000000000000 > 0)
result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128;
if (x & 0x800000000000 > 0)
result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128;
if (x & 0x400000000000 > 0)
result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128;
if (x & 0x200000000000 > 0)
result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128;
if (x & 0x100000000000 > 0)
result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128;
if (x & 0x80000000000 > 0)
result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128;
if (x & 0x40000000000 > 0)
result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128;
if (x & 0x20000000000 > 0)
result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128;
if (x & 0x10000000000 > 0)
result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128;
if (x & 0x8000000000 > 0)
result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128;
if (x & 0x4000000000 > 0)
result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128;
if (x & 0x2000000000 > 0)
result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128;
if (x & 0x1000000000 > 0)
result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128;
if (x & 0x800000000 > 0)
result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128;
if (x & 0x400000000 > 0)
result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128;
if (x & 0x200000000 > 0)
result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128;
if (x & 0x100000000 > 0)
result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128;
if (x & 0x80000000 > 0)
result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128;
if (x & 0x40000000 > 0)
result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128;
if (x & 0x20000000 > 0)
result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128;
if (x & 0x10000000 > 0)
result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128;
if (x & 0x8000000 > 0)
result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128;
if (x & 0x4000000 > 0)
result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128;
if (x & 0x2000000 > 0)
result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128;
if (x & 0x1000000 > 0)
result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128;
if (x & 0x800000 > 0)
result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128;
if (x & 0x400000 > 0)
result = result * 0x100000000002C5C85FDF477B662B26945 >> 128;
if (x & 0x200000 > 0)
result = result * 0x10000000000162E42FEFA3AE53369388C >> 128;
if (x & 0x100000 > 0)
result = result * 0x100000000000B17217F7D1D351A389D40 >> 128;
if (x & 0x80000 > 0)
result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128;
if (x & 0x40000 > 0)
result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128;
if (x & 0x20000 > 0)
result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128;
if (x & 0x10000 > 0)
result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128;
if (x & 0x8000 > 0)
result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128;
if (x & 0x4000 > 0)
result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128;
if (x & 0x2000 > 0)
result = result * 0x1000000000000162E42FEFA39F02B772C >> 128;
if (x & 0x1000 > 0)
result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128;
if (x & 0x800 > 0)
result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128;
if (x & 0x400 > 0)
result = result * 0x100000000000002C5C85FDF473DEA871F >> 128;
if (x & 0x200 > 0)
result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128;
if (x & 0x100 > 0)
result = result * 0x100000000000000B17217F7D1CF79E949 >> 128;
if (x & 0x80 > 0)
result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128;
if (x & 0x40 > 0)
result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128;
if (x & 0x20 > 0)
result = result * 0x100000000000000162E42FEFA39EF366F >> 128;
if (x & 0x10 > 0)
result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128;
if (x & 0x8 > 0)
result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128;
if (x & 0x4 > 0)
result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128;
if (x & 0x2 > 0)
result = result * 0x1000000000000000162E42FEFA39EF358 >> 128;
if (x & 0x1 > 0)
result = result * 0x10000000000000000B17217F7D1CF79AB >> 128;
result >>= 63 - (x >> 64);
require (result <= uint256 (MAX_64x64));
return int128 (result);
}
function exp (int128 x) internal pure returns (int128) {
require (x < 0x400000000000000000);
if (x < -0x400000000000000000) return 0;
return exp_2 (
int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128));
}
function divuu (uint256 x, uint256 y) private pure returns (uint128) {
require (y != 0);
uint256 result;
if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
result = (x << 64) / y;
else {
uint256 msb = 192;
uint256 xc = x >> 192;
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1;
result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1);
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 hi = result * (y >> 128);
uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 xh = x >> 192;
uint256 xl = x << 64;
if (xl < lo) xh -= 1;
xl -= lo;
lo = hi << 128;
if (xl < lo) xh -= 1;
xl -= lo;
assert (xh == hi >> 128);
result += xl / y;
}
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return uint128 (result);
}
function powu (uint256 x, uint256 y) private pure returns (uint256) {
if (y == 0) return 0x80000000000000000000000000000000;
else if (x == 0) return 0;
else {
int256 msb = 0;
uint256 xc = x;
if (xc >= 0x100000000000000000000000000000000) { xc >>= 128; msb += 128; }
if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; }
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1;
int256 xe = msb - 127;
if (xe > 0) x >>= xe;
else x <<= -xe;
uint256 result = 0x80000000000000000000000000000000;
int256 re = 0;
while (y > 0) {
if (y & 1 > 0) {
result = result * x;
y -= 1;
re += xe;
if (result >=
0x8000000000000000000000000000000000000000000000000000000000000000) {
result >>= 128;
re += 1;
} else result >>= 127;
if (re < -127) return 0;
require (re < 128);
} else {
x = x * x;
y >>= 1;
xe <<= 1;
if (x >=
0x8000000000000000000000000000000000000000000000000000000000000000) {
x >>= 128;
xe += 1;
} else x >>= 127;
if (xe < -127) return 0;
require (xe < 128);
}
}
if (re > 0) result <<= re;
else if (re < 0) result >>= -re;
return result;
}
}
function sqrtu (uint256 x, uint256 r) private pure returns (uint128) {
if (x == 0) return 0;
else {
require (r > 0);
while (true) {
uint256 rr = x / r;
if (r == rr || r + 1 == rr) return uint128 (r);
else if (r == rr + 1) return uint128 (rr);
r = r + rr + 1 >> 1;
}
}
}
}
文件 2 的 13:Context.sol
pragma solidity ^0.5.0;
contract Context {
constructor () internal { }
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
function _msgData() internal view returns (bytes memory) {
this;
return msg.data;
}
}
文件 3 的 13:IERC20.sol
pragma solidity ^0.5.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function mint(address account, uint amount) external;
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, 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 sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 4 的 13:Ownable.sol
pragma solidity ^0.5.0;
import "./Context.sol";
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
文件 5 的 13:SafeMath.sol
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
文件 6 的 13:SavingAccountParameters.sol
pragma solidity >= 0.5.0 < 0.6.0;
contract SavingAccountParameters {
string public ratesURL;
string public tokenNames;
address[] public tokenAddresses;
constructor() public payable{
tokenNames = "ETH,USDT,PROS";
tokenAddresses = new address[](3);
tokenAddresses[0] = 0x000000000000000000000000000000000000000E;
tokenAddresses[1] = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
tokenAddresses[2] = 0x306Dd7CD66d964f598B4D2ec92b5a9B275D7fEb3;
}
function getTokenAddresses() public view returns(address[] memory){
return tokenAddresses;
}
}
文件 7 的 13:SignedSafeMath.sol
pragma solidity ^0.5.0;
library SignedSafeMath {
int256 constant private INT256_MIN = -2**255;
function mul(int256 a, int256 b) internal pure returns (int256) {
if (a == 0) {
return 0;
}
require(!(a == -1 && b == INT256_MIN), "SignedSafeMath: multiplication overflow");
int256 c = a * b;
require(c / a == b, "SignedSafeMath: multiplication overflow");
return c;
}
function div(int256 a, int256 b) internal pure returns (int256) {
require(b != 0, "SignedSafeMath: division by zero");
require(!(b == -1 && a == INT256_MIN), "SignedSafeMath: division overflow");
int256 c = a / b;
return c;
}
function sub(int256 a, int256 b) internal pure returns (int256) {
int256 c = a - b;
require((b >= 0 && c <= a) || (b < 0 && c > a), "SignedSafeMath: subtraction overflow");
return c;
}
function add(int256 a, int256 b) internal pure returns (int256) {
int256 c = a + b;
require((b >= 0 && c >= a) || (b < 0 && c < a), "SignedSafeMath: addition overflow");
return c;
}
}
文件 8 的 13:SymbolsLib.sol
pragma solidity >= 0.5.0 < 0.6.0;
import "./SafeMath.sol";
import "./strings.sol";
library SymbolsLib {
using SafeMath for uint256;
struct Symbols {
uint count;
mapping(uint => string) indexToSymbol;
mapping(string => uint256) symbolToPrices;
mapping(address => string) addressToSymbol;
mapping(string => address) symbolToAddress;
string ratesURL;
}
function initialize(Symbols storage self, string memory ratesURL, string memory tokenNames, address[] memory tokenAddresses) public {
strings.slice memory delim = strings.toSlice(",");
strings.slice memory tokensList = strings.toSlice(tokenNames);
self.count = strings.count(tokensList, delim) + 1;
require(self.count == tokenAddresses.length);
self.ratesURL = ratesURL;
for(uint i = 0; i < self.count; i++) {
strings.slice memory token;
strings.split(tokensList, delim, token);
address tokenAddress = tokenAddresses[i];
string memory tokenName = strings.toString(token);
self.indexToSymbol[i] = tokenName;
self.addressToSymbol[tokenAddress] = tokenName;
self.symbolToAddress[tokenName] = tokenAddress;
}
}
function getCoinLength(Symbols storage self) public view returns (uint length){
return self.count;
}
function addressFromIndex(Symbols storage self, uint index) public view returns(address) {
require(index < self.count, "coinIndex must be smaller than the coins length.");
return self.symbolToAddress[self.indexToSymbol[index]];
}
function priceFromIndex(Symbols storage self, uint index) public view returns(uint256) {
require(index < self.count, "coinIndex must be smaller than the coins length.");
return self.symbolToPrices[self.indexToSymbol[index]];
}
function priceFromAddress(Symbols storage self, address tokenAddress) public view returns(uint256) {
return self.symbolToPrices[self.addressToSymbol[tokenAddress]];
}
function setPrice(Symbols storage self, uint index, uint256 price) public {
require(index < self.count, "coinIndex must be smaller than the coins length.");
self.symbolToPrices[self.indexToSymbol[index]] = price;
}
function isEth(Symbols storage self, address tokenAddress) public view returns(bool) {
return self.symbolToAddress["ETH"] == tokenAddress;
}
function parseRates(Symbols storage self, string memory result,uint256 who) internal {
strings.slice memory delim = strings.toSlice(",");
strings.slice memory startChar = strings.toSlice("[");
strings.slice memory endChar = strings.toSlice("]");
strings.slice memory substring = strings.until(strings.beyond(strings.toSlice(result), startChar), endChar);
uint count = strings.count(substring, delim) + 1;
for(uint i = (who-1)*3; i < (who-1)*3+3; i++) {
strings.slice memory token;
strings.split(substring, delim, token);
setPrice(self, i, stringToUint(strings.toString(token)));
}
}
function parseRatesbyself(Symbols storage self, string memory result) internal {
strings.slice memory delim = strings.toSlice(",");
strings.slice memory startChar = strings.toSlice("[");
strings.slice memory endChar = strings.toSlice("]");
strings.slice memory substring = strings.until(strings.beyond(strings.toSlice(result), startChar), endChar);
uint count = strings.count(substring, delim) + 1;
for(uint i = 0; i < count; i++) {
strings.slice memory token;
strings.split(substring, delim, token);
setPrice(self, i, stringToUint(strings.toString(token)));
}
}
function stringToUint(string memory numString) private pure returns(uint256 number) {
bytes memory numBytes = bytes(numString);
bool isFloat = false;
uint times = 6;
number = 0;
for(uint256 i = 0; i < numBytes.length; i ++) {
if (numBytes[i] >= '0' && numBytes[i] <= '9' && times > 0) {
number *= 10;
number = number + uint8(numBytes[i]) - 48;
if (isFloat) {
times --;
}
} else if (numBytes[i] == '.') {
isFloat = true;
continue;
}
}
while (times > 0) {
number *= 10;
times --;
}
return number;
}
}
文件 9 的 13:TokenInfoLib.sol
pragma solidity >= 0.5.0 < 0.6.0;
import "./SafeMath.sol";
import "./SignedSafeMath.sol";
library TokenInfoLib {
using SafeMath for uint256;
using SignedSafeMath for int256;
struct TokenInfo {
int256 balance;
int256 interest;
uint256 rate;
uint256 lastModification;
}
uint256 constant BASE = 10**12;
int256 constant POSITIVE = 1;
int256 constant NEGATIVE = -1;
function totalAmount(TokenInfo storage self, uint256 currentTimestamp) public view returns(int256) {
return self.balance.add(viewInterest(self, currentTimestamp));
}
function totalnumber(TokenInfo storage self)public view returns(int256){
return self.balance;
}
function getCurrentTotalAmount(TokenInfo storage self) public view returns(int256) {
return self.balance.add(self.interest);
}
function getInterest(TokenInfo storage self,uint256 currentTimestamp)public view returns(int256){
return viewInterest(self, currentTimestamp);
}
function minusAmount(TokenInfo storage self, uint256 amount, uint256 rate, uint256 currentTimestamp) public {
resetInterest(self, currentTimestamp);
int256 _amount = int256(amount);
if (self.balance + self.interest > 0) {
if (self.interest >= _amount) {
self.interest = self.interest.sub(_amount);
_amount = 0;
} else if (self.balance.add(self.interest) >= _amount){
self.balance = self.balance.sub(_amount.sub(self.interest));
self.interest = 0;
_amount = 0;
} else {
_amount = _amount.sub(self.balance.add(self.interest));
self.balance = 0;
self.interest = 0;
self.rate = 0;
}
}
if (_amount > 0) {
require(self.balance.add(self.interest) <= 0, "To minus amount, the total balance must be smaller than 0.");
self.rate = mixRate(self, _amount, rate);
self.balance = self.balance.sub(_amount);
}
}
function addAmount(TokenInfo storage self, uint256 amount, uint256 rate, uint256 currentTimestamp) public returns(int256) {
resetInterest(self, currentTimestamp);
int256 _amount = int256(amount);
if (self.balance.add(self.interest) < 0) {
if (self.interest.add(_amount) <= 0) {
self.interest = self.interest.add(_amount);
_amount = 0;
} else if (self.balance.add(self.interest).add(_amount) <= 0) {
self.balance = self.balance.add(_amount.add(self.interest));
self.interest = 0;
_amount = 0;
} else {
_amount = _amount.add(self.balance.add(self.interest));
self.balance = 0;
self.interest = 0;
self.rate = 0;
}
}
if (_amount > 0) {
require(self.balance.add(self.interest) >= 0, "To add amount, the total balance must be larger than 0.");
self.rate = mixRate(self, _amount, rate);
self.balance = self.balance.add(_amount);
}
return totalAmount(self, currentTimestamp);
}
function mixRate(TokenInfo storage self, int256 amount, uint256 rate) private view returns (uint256){
uint256 _balance = self.balance >= 0 ? uint256(self.balance) : uint256(-self.balance);
uint256 _amount = amount >= 0 ? uint256(amount) : uint256(-amount);
return _balance.mul(self.rate).add(_amount.mul(rate)).div(_balance + _amount);
}
function resetInterest(TokenInfo storage self, uint256 currentTimestamp) public {
self.interest = viewInterest(self, currentTimestamp);
self.lastModification = currentTimestamp;
}
function viewInterest(TokenInfo storage self, uint256 currentTimestamp) public view returns(int256) {
int256 _sign = self.balance < 0 ? NEGATIVE : POSITIVE;
uint256 _balance = self.balance >= 0 ? uint256(self.balance) : uint256(-self.balance);
uint256 _difference = currentTimestamp.sub(self.lastModification);
return self.interest
.add(int256(_balance.mul(self.rate).mul(_difference).div(BASE)))
.mul(_sign);
}
}
文件 10 的 13:bkk.sol
pragma solidity ^0.5.0;
interface bkk {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external ;
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 11 的 13:strings.sol
pragma solidity >= 0.5.0 < 0.6.0;
library strings {
struct slice {
uint _len;
uint _ptr;
}
function memcpy(uint dest, uint src, uint len) private pure {
for(; len >= 32; len -= 32) {
assembly {
mstore(dest, mload(src))
}
dest += 32;
src += 32;
}
uint mask = 256 ** (32 - len) - 1;
assembly {
let srcpart := and(mload(src), not(mask))
let destpart := and(mload(dest), mask)
mstore(dest, or(destpart, srcpart))
}
}
function toSlice(string memory self) internal pure returns (slice memory) {
uint ptr;
assembly {
ptr := add(self, 0x20)
}
return slice(bytes(self).length, ptr);
}
function len(bytes32 self) internal pure returns (uint) {
uint ret;
if (self == 0)
return 0;
if (uint(self) & 0xffffffffffffffffffffffffffffffff == 0) {
ret += 16;
self = bytes32(uint(self) / 0x100000000000000000000000000000000);
}
if (uint(self) & 0xffffffffffffffff == 0) {
ret += 8;
self = bytes32(uint(self) / 0x10000000000000000);
}
if (uint(self) & 0xffffffff == 0) {
ret += 4;
self = bytes32(uint(self) / 0x100000000);
}
if (uint(self) & 0xffff == 0) {
ret += 2;
self = bytes32(uint(self) / 0x10000);
}
if (uint(self) & 0xff == 0) {
ret += 1;
}
return 32 - ret;
}
function toSliceB32(bytes32 self) internal pure returns (slice memory ret) {
assembly {
let ptr := mload(0x40)
mstore(0x40, add(ptr, 0x20))
mstore(ptr, self)
mstore(add(ret, 0x20), ptr)
}
ret._len = len(self);
}
function copy(slice memory self) internal pure returns (slice memory) {
return slice(self._len, self._ptr);
}
function toString(slice memory self) internal pure returns (string memory) {
string memory ret = new string(self._len);
uint retptr;
assembly { retptr := add(ret, 32) }
memcpy(retptr, self._ptr, self._len);
return ret;
}
function len(slice memory self) internal pure returns (uint l) {
uint ptr = self._ptr - 31;
uint end = ptr + self._len;
for (l = 0; ptr < end; l++) {
uint8 b;
assembly { b := and(mload(ptr), 0xFF) }
if (b < 0x80) {
ptr += 1;
} else if(b < 0xE0) {
ptr += 2;
} else if(b < 0xF0) {
ptr += 3;
} else if(b < 0xF8) {
ptr += 4;
} else if(b < 0xFC) {
ptr += 5;
} else {
ptr += 6;
}
}
}
function empty(slice memory self) internal pure returns (bool) {
return self._len == 0;
}
function compare(slice memory self, slice memory other) internal pure returns (int) {
uint shortest = self._len;
if (other._len < self._len)
shortest = other._len;
uint selfptr = self._ptr;
uint otherptr = other._ptr;
for (uint idx = 0; idx < shortest; idx += 32) {
uint a;
uint b;
assembly {
a := mload(selfptr)
b := mload(otherptr)
}
if (a != b) {
uint256 mask = uint256(-1);
if(shortest < 32) {
mask = ~(2 ** (8 * (32 - shortest + idx)) - 1);
}
uint256 diff = (a & mask) - (b & mask);
if (diff != 0)
return int(diff);
}
selfptr += 32;
otherptr += 32;
}
return int(self._len) - int(other._len);
}
function equals(slice memory self, slice memory other) internal pure returns (bool) {
return compare(self, other) == 0;
}
function nextRune(slice memory self, slice memory rune) internal pure returns (slice memory) {
rune._ptr = self._ptr;
if (self._len == 0) {
rune._len = 0;
return rune;
}
uint l;
uint b;
assembly { b := and(mload(sub(mload(add(self, 32)), 31)), 0xFF) }
if (b < 0x80) {
l = 1;
} else if(b < 0xE0) {
l = 2;
} else if(b < 0xF0) {
l = 3;
} else {
l = 4;
}
if (l > self._len) {
rune._len = self._len;
self._ptr += self._len;
self._len = 0;
return rune;
}
self._ptr += l;
self._len -= l;
rune._len = l;
return rune;
}
function nextRune(slice memory self) internal pure returns (slice memory ret) {
nextRune(self, ret);
}
function ord(slice memory self) internal pure returns (uint ret) {
if (self._len == 0) {
return 0;
}
uint word;
uint length;
uint divisor = 2 ** 248;
assembly { word:= mload(mload(add(self, 32))) }
uint b = word / divisor;
if (b < 0x80) {
ret = b;
length = 1;
} else if(b < 0xE0) {
ret = b & 0x1F;
length = 2;
} else if(b < 0xF0) {
ret = b & 0x0F;
length = 3;
} else {
ret = b & 0x07;
length = 4;
}
if (length > self._len) {
return 0;
}
for (uint i = 1; i < length; i++) {
divisor = divisor / 256;
b = (word / divisor) & 0xFF;
if (b & 0xC0 != 0x80) {
return 0;
}
ret = (ret * 64) | (b & 0x3F);
}
return ret;
}
function keccak(slice memory self) internal pure returns (bytes32 ret) {
assembly {
ret := keccak256(mload(add(self, 32)), mload(self))
}
}
function startsWith(slice memory self, slice memory needle) internal pure returns (bool) {
if (self._len < needle._len) {
return false;
}
if (self._ptr == needle._ptr) {
return true;
}
bool equal;
assembly {
let length := mload(needle)
let selfptr := mload(add(self, 0x20))
let needleptr := mload(add(needle, 0x20))
equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))
}
return equal;
}
function beyond(slice memory self, slice memory needle) internal pure returns (slice memory) {
if (self._len < needle._len) {
return self;
}
bool equal = true;
if (self._ptr != needle._ptr) {
assembly {
let length := mload(needle)
let selfptr := mload(add(self, 0x20))
let needleptr := mload(add(needle, 0x20))
equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))
}
}
if (equal) {
self._len -= needle._len;
self._ptr += needle._len;
}
return self;
}
function endsWith(slice memory self, slice memory needle) internal pure returns (bool) {
if (self._len < needle._len) {
return false;
}
uint selfptr = self._ptr + self._len - needle._len;
if (selfptr == needle._ptr) {
return true;
}
bool equal;
assembly {
let length := mload(needle)
let needleptr := mload(add(needle, 0x20))
equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))
}
return equal;
}
function until(slice memory self, slice memory needle) internal pure returns (slice memory) {
if (self._len < needle._len) {
return self;
}
uint selfptr = self._ptr + self._len - needle._len;
bool equal = true;
if (selfptr != needle._ptr) {
assembly {
let length := mload(needle)
let needleptr := mload(add(needle, 0x20))
equal := eq(keccak256(selfptr, length), keccak256(needleptr, length))
}
}
if (equal) {
self._len -= needle._len;
}
return self;
}
function findPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {
uint ptr = selfptr;
uint idx;
if (needlelen <= selflen) {
if (needlelen <= 32) {
bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));
bytes32 needledata;
assembly { needledata := and(mload(needleptr), mask) }
uint end = selfptr + selflen - needlelen;
bytes32 ptrdata;
assembly { ptrdata := and(mload(ptr), mask) }
while (ptrdata != needledata) {
if (ptr >= end)
return selfptr + selflen;
ptr++;
assembly { ptrdata := and(mload(ptr), mask) }
}
return ptr;
} else {
bytes32 hash;
assembly { hash := keccak256(needleptr, needlelen) }
for (idx = 0; idx <= selflen - needlelen; idx++) {
bytes32 testHash;
assembly { testHash := keccak256(ptr, needlelen) }
if (hash == testHash)
return ptr;
ptr += 1;
}
}
}
return selfptr + selflen;
}
function rfindPtr(uint selflen, uint selfptr, uint needlelen, uint needleptr) private pure returns (uint) {
uint ptr;
if (needlelen <= selflen) {
if (needlelen <= 32) {
bytes32 mask = bytes32(~(2 ** (8 * (32 - needlelen)) - 1));
bytes32 needledata;
assembly { needledata := and(mload(needleptr), mask) }
ptr = selfptr + selflen - needlelen;
bytes32 ptrdata;
assembly { ptrdata := and(mload(ptr), mask) }
while (ptrdata != needledata) {
if (ptr <= selfptr)
return selfptr;
ptr--;
assembly { ptrdata := and(mload(ptr), mask) }
}
return ptr + needlelen;
} else {
bytes32 hash;
assembly { hash := keccak256(needleptr, needlelen) }
ptr = selfptr + (selflen - needlelen);
while (ptr >= selfptr) {
bytes32 testHash;
assembly { testHash := keccak256(ptr, needlelen) }
if (hash == testHash)
return ptr + needlelen;
ptr -= 1;
}
}
}
return selfptr;
}
function find(slice memory self, slice memory needle) internal pure returns (slice memory) {
uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr);
self._len -= ptr - self._ptr;
self._ptr = ptr;
return self;
}
function rfind(slice memory self, slice memory needle) internal pure returns (slice memory) {
uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr);
self._len = ptr - self._ptr;
return self;
}
function split(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) {
uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr);
token._ptr = self._ptr;
token._len = ptr - self._ptr;
if (ptr == self._ptr + self._len) {
self._len = 0;
} else {
self._len -= token._len + needle._len;
self._ptr = ptr + needle._len;
}
return token;
}
function split(slice memory self, slice memory needle) internal pure returns (slice memory token) {
split(self, needle, token);
}
function rsplit(slice memory self, slice memory needle, slice memory token) internal pure returns (slice memory) {
uint ptr = rfindPtr(self._len, self._ptr, needle._len, needle._ptr);
token._ptr = ptr;
token._len = self._len - (ptr - self._ptr);
if (ptr == self._ptr) {
self._len = 0;
} else {
self._len -= token._len + needle._len;
}
return token;
}
function rsplit(slice memory self, slice memory needle) internal pure returns (slice memory token) {
rsplit(self, needle, token);
}
function count(slice memory self, slice memory needle) internal pure returns (uint cnt) {
uint ptr = findPtr(self._len, self._ptr, needle._len, needle._ptr) + needle._len;
while (ptr <= self._ptr + self._len) {
cnt++;
ptr = findPtr(self._len - (ptr - self._ptr), ptr, needle._len, needle._ptr) + needle._len;
}
}
function contains(slice memory self, slice memory needle) internal pure returns (bool) {
return rfindPtr(self._len, self._ptr, needle._len, needle._ptr) != self._ptr;
}
function concat(slice memory self, slice memory other) internal pure returns (string memory) {
string memory ret = new string(self._len + other._len);
uint retptr;
assembly { retptr := add(ret, 32) }
memcpy(retptr, self._ptr, self._len);
memcpy(retptr + self._len, other._ptr, other._len);
return ret;
}
function join(slice memory self, slice[] memory parts) internal pure returns (string memory) {
if (parts.length == 0)
return "";
uint length = self._len * (parts.length - 1);
for(uint i = 0; i < parts.length; i++)
length += parts[i]._len;
string memory ret = new string(length);
uint retptr;
assembly { retptr := add(ret, 32) }
for(uint i = 0; i < parts.length; i++) {
memcpy(retptr, parts[i]._ptr, parts[i]._len);
retptr += parts[i]._len;
if (i < parts.length - 1) {
memcpy(retptr, self._ptr, self._len);
retptr += self._len;
}
}
return ret;
}
}
文件 12 的 13:tokenbasic.sol
pragma solidity ^0.5.0;
interface basic{
function allowance(address owner, address spender) external view returns (uint);
function transferFrom(address from, address to, uint value) external;
function approve(address spender, uint value) external;
event Approval(address indexed owner, address indexed spender, uint value);
function totalSupply() external view returns (uint);
function balanceOf(address who) external view returns (uint);
function transfer(address to, uint value) external;
event Transfer(address indexed from, address indexed to, uint value);
}
文件 13 的 13:yam.sol
pragma solidity >= 0.5.0 < 0.6.0;
import "./TokenInfoLib.sol";
import "./SymbolsLib.sol";
import "./SafeMath.sol";
import "./SignedSafeMath.sol";
import "./Ownable.sol";
import "./SavingAccountParameters.sol";
import "./IERC20.sol";
import "./ABDK.sol";
import "./tokenbasic.sol";
import "./bkk.sol";
pragma solidity ^0.5.5;
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function toPayable(address account) internal pure returns (address payable) {
return address(uint160(account));
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call.value(amount)("");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
pragma solidity ^0.5.0;
library SafeERC20 {
using SafeMath for uint256;
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require((value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).add(value);
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function callOptionalReturn(IERC20 token, bytes memory data) private {
require(address(token).isContract(), "SafeERC20: call to non-contract");
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
library Math {
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a >= b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
}
}
interface AllPool{
function is_Re(address user) view external returns(bool);
function get_Address_pool(address user) view external returns(address);
}
interface IPlayerBook {
function settleReward( address from,uint256 amount ) external returns (uint256);
}
contract SavingAccount is Ownable{
using TokenInfoLib for TokenInfoLib.TokenInfo;
using SymbolsLib for SymbolsLib.Symbols;
using SafeMath for uint256;
using SignedSafeMath for int256;
using SafeERC20 for IERC20;
event depositTokened(address onwer,uint256 amount,address tokenaddress);
event withdrawed(address onwer,uint256 amount,address tokenaddress);
event RewardAdded(uint256 reward);
event RewardPaid(address indexed user, uint256 reward);
bool _hasStart = false;
uint256 public _initReward = 0;
IERC20 public _pros = IERC20(0x306Dd7CD66d964f598B4D2ec92b5a9B275D7fEb3);
address public _teamWallet = 0x89941E92E414c88179a830af5c10bde0E9245158;
address public _playbook = 0x21A4086a6Cdb332c851B76cccD21aCAB6428D9E4;
address public _allpool = 0xC682bD99eE552B6f7d931aFee2A9425806e155E9;
address public _ETH = 0x000000000000000000000000000000000000000E;
address public _USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
address public _PROS = 0x306Dd7CD66d964f598B4D2ec92b5a9B275D7fEb3;
uint256 DURATION = 1 days;
int128 dayNums = 0;
int128 baseReward = 80000;
uint256 public base_ = 20*10e3;
uint256 public rate_forReward = 1;
uint256 public base_Rate_Reward = 100;
struct Account {
mapping(address => TokenInfoLib.TokenInfo) tokenInfos;
bool active;
}
mapping(address => Account) accounts;
mapping(address => int256) totalDeposits;
mapping(address => int256) totalLoans;
mapping(address => int256) totalCollateral;
mapping(address => bool) loansAccount;
address[] activeAccounts;
address[] activeLoansAccount;
mapping(address => uint256)_initTokenReward;
uint256 public _startTime = now + 365 days;
uint256 public _periodFinish = 0;
uint256 public _rewardRate = 0;
mapping(address =>uint256) public _rewardRateList;
mapping(address=>uint256) public _lastUpdateTime;
mapping(address=>uint256) public _rewardPerTokenStored;
uint256 public _teamRewardRate = 0;
uint256 public _poolRewardRate = 0;
uint256 public _baseRate = 10000;
uint256 public _punishTime = 10 days;
uint256 public one_Rate = 90;
uint256 public sec_Rate = 5;
uint256 public thr_Rate = 5;
uint256 public BASE_RATE_FORREWARD = 100;
mapping(address => mapping(address=>uint256)) public _userRewardPerTokenPaid;
mapping(address => mapping(address=>uint256)) public _rewards;
mapping(address => mapping(address=>uint256)) public _lastStakedTime;
SymbolsLib.Symbols symbols;
int256 constant BASE = 10**6;
int BORROW_LTV = 66;
int LIQUIDATE_THREADHOLD = 85;
constructor() public {
SavingAccountParameters params = new SavingAccountParameters();
address[] memory tokenAddresses = params.getTokenAddresses();
symbols.initialize(params.ratesURL(), params.tokenNames(), tokenAddresses);
}
function setprosToken(IERC20 token) public onlyOwner{
_pros = token;
}
function setAllpool(address pool)public onlyOwner {
_allpool = pool;
}
function setTeamToken(address tokenaddress) public onlyOwner{
_teamWallet = tokenaddress;
}
function set_tokens(address eth,address usdt,address pros) public onlyOwner{
_ETH = eth;
_USDT = usdt;
_PROS = pros;
}
function setPlaybook(address playbook) public onlyOwner{
_playbook = playbook;
}
function setRate_Reward(uint256 one,uint256 sec,uint256 thr,uint256 total)public onlyOwner{
one_Rate = one;
sec_Rate = sec;
thr_Rate = thr;
BASE_RATE_FORREWARD = total;
}
function() external payable {}
function getAccountTotalUsdValue(address accountAddr) public view returns (int256 usdValue) {
return getAccountTotalUsdValue(accountAddr, true).add(getAccountTotalUsdValue(accountAddr, false));
}
function getAccountTotalUsdValue(address accountAddr, bool isPositive) private view returns (int256 usdValue){
int256 totalUsdValue = 0;
for(uint i = 0; i < getCoinLength(); i++) {
if (isPositive && accounts[accountAddr].tokenInfos[symbols.addressFromIndex(i)].totalAmount(block.timestamp) >= 0) {
totalUsdValue = totalUsdValue.add(
accounts[accountAddr].tokenInfos[symbols.addressFromIndex(i)].totalAmount(block.timestamp)
.mul(int256(symbols.priceFromIndex(i)))
.div(BASE)
);
}
if (!isPositive && accounts[accountAddr].tokenInfos[symbols.addressFromIndex(i)].totalAmount(block.timestamp) < 0) {
totalUsdValue = totalUsdValue.add(
accounts[accountAddr].tokenInfos[symbols.addressFromIndex(i)].totalAmount(block.timestamp)
.mul(int256(symbols.priceFromIndex(i)))
.div(BASE)
);
}
}
return totalUsdValue;
}
function rewardPerToken(address tokenID) public view returns (uint256) {
if (totalDeposits[tokenID] == 0) {
return _rewardPerTokenStored[tokenID];
}
return
_rewardPerTokenStored[tokenID].add(
lastTimeRewardApplicable()
.sub(_lastUpdateTime[tokenID])
.mul(_rewardRateList[tokenID])
.mul(1e18)
.div(uint256(totalDeposits[tokenID]))
);
}
function lastTimeRewardApplicable() public view returns (uint256) {
return Math.min(block.timestamp, _periodFinish);
}
function earned(address account,address tokenID) public view returns (uint256) {
return
uint256(tokenBalanceOf(tokenID,account))
.mul(rewardPerToken(tokenID).sub(_userRewardPerTokenPaid[tokenID][account]))
.div(1e18)
.add(_rewards[tokenID][account]);
}
function earned(address account) public view returns (uint256) {
uint coinsLen = getCoinLength();
uint256 Total;
for (uint i = 0; i < coinsLen; i++) {
address tokenAddress = symbols.addressFromIndex(i);
Total = Total.add(earned(account,tokenAddress));
}
return Total;
}
modifier checkHalve() {
if (block.timestamp >= _periodFinish) {
update_initreward();
_pros.mint(address(this), _initReward);
_rewardRate = _initReward.div(DURATION*3);
_rewardRateList[address(_PROS)] = _initReward.mul(one_Rate).div(DURATION*BASE_RATE_FORREWARD);
_rewardRateList[address(_USDT)] = _initReward.mul(sec_Rate).div(DURATION*BASE_RATE_FORREWARD);
_rewardRateList[address(_ETH)] = _initReward.mul(thr_Rate).div(DURATION*BASE_RATE_FORREWARD);
_periodFinish = block.timestamp.add(DURATION);
}
_;
}
modifier checkStart() {
require(block.timestamp > _startTime, "not start");
_;
}
modifier updateReward(address account,address tokenID) {
_rewardPerTokenStored[tokenID] = rewardPerToken(tokenID);
_lastUpdateTime[tokenID] = lastTimeRewardApplicable();
if (account != address(0)) {
_rewards[tokenID][account] = earned(account,tokenID);
_userRewardPerTokenPaid[tokenID][account] = _rewardPerTokenStored[tokenID];
}
_;
}
modifier isRegister(){
require(AllPool(_allpool).is_Re(msg.sender)==true,"address not register or name already register");
_;
}
modifier updateRewardAll(address account) {
uint coinsLen = getCoinLength();
address[] memory tokens = new address[](coinsLen);
for (uint i = 0; i < coinsLen; i++) {
address tokenAddress = symbols.addressFromIndex(i);
tokens[i] = tokenAddress;
}
for(uint i=0;i<3;i++){
address tokenID = tokens[i];
_rewardPerTokenStored[tokenID] = rewardPerToken(tokenID);
_lastUpdateTime[tokenID] = lastTimeRewardApplicable();
if (account != address(0)) {
_rewards[tokenID][account] = earned(account,tokenID);
_userRewardPerTokenPaid[tokenID][account] = _rewardPerTokenStored[tokenID];
}
}
_;
}
function getMarketState() public view returns (address[] memory addresses,
int256[] memory deposits
)
{
uint coinsLen = getCoinLength();
addresses = new address[](coinsLen);
deposits = new int256[](coinsLen);
for (uint i = 0; i < coinsLen; i++) {
address tokenAddress = symbols.addressFromIndex(i);
addresses[i] = tokenAddress;
deposits[i] = totalDeposits[tokenAddress];
}
return (addresses, deposits);
}
function getTokenState(address tokenAddress) public view returns (int256 deposits, int256 loans, int256 collateral)
{
return (totalDeposits[tokenAddress], totalLoans[tokenAddress], totalCollateral[tokenAddress]);
}
function getBalances() public view returns (address[] memory addresses, int256[] memory balances)
{
uint coinsLen = getCoinLength();
addresses = new address[](coinsLen);
balances = new int256[](coinsLen);
for (uint i = 0; i < coinsLen; i++) {
address tokenAddress = symbols.addressFromIndex(i);
addresses[i] = tokenAddress;
balances[i] = tokenBalanceOf(tokenAddress);
}
return (addresses, balances);
}
function getActiveAccounts() public view returns (address[] memory) {
return activeAccounts;
}
function tokenBalanceOf(address tokenAddress,address account) public view returns (int256 amount) {
return accounts[account].tokenInfos[tokenAddress].totalAmount(block.timestamp);
}
function getCoinLength() public view returns (uint256 length){
return symbols.getCoinLength();
}
function tokenBalanceOf(address tokenAddress) public view returns (int256 amount) {
return accounts[msg.sender].tokenInfos[tokenAddress].totalAmount(block.timestamp);
}
function getCoinAddress(uint256 coinIndex) public view returns (address) {
return symbols.addressFromIndex(coinIndex);
}
function depositToken(address tokenAddress, uint256 amount) updateReward(msg.sender,tokenAddress) checkHalve checkStart isRegister public payable {
TokenInfoLib.TokenInfo storage tokenInfo = accounts[msg.sender].tokenInfos[tokenAddress];
if (!accounts[msg.sender].active) {
accounts[msg.sender].active = true;
activeAccounts.push(msg.sender);
}
int256 currentBalance = tokenInfo.getCurrentTotalAmount();
require(currentBalance >= 0,
"Balance of the token must be zero or positive. To pay negative balance, please use repay button.");
uint256 LastRatio = 0;
int256 depositedAmount = tokenInfo.addAmount(amount, LastRatio, block.timestamp) - currentBalance;
totalDeposits[tokenAddress] = totalDeposits[tokenAddress].add(depositedAmount);
emit depositTokened(msg.sender,amount,tokenAddress);
receive(msg.sender, amount, amount,tokenAddress);
}
function withdrawToken(address tokenAddress, uint256 amount) updateReward(msg.sender,tokenAddress) checkStart checkHalve public payable {
require(accounts[msg.sender].active, "Account not active, please deposit first.");
TokenInfoLib.TokenInfo storage tokenInfo = accounts[msg.sender].tokenInfos[tokenAddress];
require(tokenInfo.totalAmount(block.timestamp) >= int256(amount), "Insufficient balance.");
require(int256(getAccountTotalUsdValue(msg.sender, false).mul(-1)).mul(100) <= (getAccountTotalUsdValue(msg.sender, true) - int256(amount.mul(symbols.priceFromAddress(tokenAddress)).div(uint256(BASE)))).mul(BORROW_LTV));
emit withdrawed(msg.sender,amount,tokenAddress);
tokenInfo.minusAmount(amount, 0, block.timestamp);
totalDeposits[tokenAddress] = totalDeposits[tokenAddress].sub(int256(amount));
totalCollateral[tokenAddress] = totalCollateral[tokenAddress].sub(int256(amount));
send(msg.sender, amount, tokenAddress);
}
function receive(address from, uint256 amount, uint256 amounttwo,address tokenAddress) private {
if (symbols.isEth(tokenAddress)) {
require(msg.value >= amounttwo, "The amount is not sent from address.");
msg.sender.transfer(msg.value-amounttwo);
} else {
require(msg.value >= 0, "msg.value must be 0 when receiving tokens");
if(tokenAddress!=_USDT ){
require(IERC20(tokenAddress).transferFrom(from, address(this), amount));
}else{
basic(tokenAddress).transferFrom(from,address(this),amount);
}
}
}
function send(address to, uint256 amount, address tokenAddress) private {
if (symbols.isEth(tokenAddress)) {
msg.sender.transfer(amount);
} else {
if(tokenAddress!=_USDT){
require(IERC20(tokenAddress).transfer(to, amount));
}else{
basic(tokenAddress).transfer(to, amount);
}
}
}
function getReward() public updateRewardAll(msg.sender) checkHalve checkStart {
uint256 reward;
uint coinsLen = getCoinLength();
address[] memory tokens = new address[](coinsLen);
for (uint i = 0; i < coinsLen; i++) {
address tokenAddress = symbols.addressFromIndex(i);
tokens[i] = tokenAddress;
reward = reward.add(earned(msg.sender,tokens[i]));
}
if (reward > 0) {
_rewards[tokens[0]][msg.sender] = 0;
_rewards[tokens[1]][msg.sender] = 0;
_rewards[tokens[2]][msg.sender] = 0;
address set_play = AllPool(_allpool).get_Address_pool(msg.sender)==0x0000000000000000000000000000000000000000?_playbook:AllPool(_allpool).get_Address_pool(msg.sender);
uint256 fee = IPlayerBook(set_play).settleReward(msg.sender,reward);
if(fee>0){
_pros.safeTransfer(set_play,fee);
}
uint256 teamReward = reward.mul(_teamRewardRate).div(_baseRate);
if(teamReward>0){
_pros.safeTransfer(_teamWallet, teamReward);
}
uint256 leftReward = reward.sub(fee).sub(teamReward);
uint256 poolReward = 0;
if(leftReward>0){
_pros.safeTransfer(msg.sender, leftReward);
}
emit RewardPaid(msg.sender,reward);
}
}
function update_initreward() private {
dayNums = dayNums + 1;
uint256 thisreward = base_.mul(rate_forReward).mul(10**18).mul((base_Rate_Reward.sub(rate_forReward))**(uint256(dayNums-1))).div(base_Rate_Reward**(uint256(dayNums)));
_initReward = uint256(thisreward);
}
function startReward(uint256 startTime)
external
onlyOwner
updateReward(address(0),address(_ETH))
{
require(_hasStart == false, "has started");
_hasStart = true;
_startTime = startTime;
update_initreward();
_rewardRate = _initReward.div(DURATION*3);
_rewardRateList[address(_PROS)] = _initReward.mul(one_Rate).div(DURATION*BASE_RATE_FORREWARD);
_rewardRateList[address(_USDT)] = _initReward.mul(sec_Rate).div(DURATION*BASE_RATE_FORREWARD);
_rewardRateList[address(_ETH)] = _initReward.mul(thr_Rate).div(DURATION*BASE_RATE_FORREWARD);
_pros.mint(address(this), _initReward);
_lastUpdateTime[address(_ETH)] = _startTime;
_lastUpdateTime[address(_USDT)] = _startTime;
_lastUpdateTime[address(_PROS)] = _startTime;
_periodFinish = _startTime.add(DURATION);
emit RewardAdded(_initReward);
}
}
{
"compilationTarget": {
"contracts/yam.sol": "SavingAccount"
},
"evmVersion": "istanbul",
"libraries": {
"SymbolsLib": "0x3414b7e8332b4da3e268ca7aa5bee6b9a25787f7",
"TokenInfoLib": "0xab2ea31dba6270584486b6d7657fbfcd10f8bfae"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"onwer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenaddress","type":"address"}],"name":"depositTokened","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"onwer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"address","name":"tokenaddress","type":"address"}],"name":"withdrawed","type":"event"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"constant":true,"inputs":[],"name":"BASE_RATE_FORREWARD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_PROS","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_USDT","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_allpool","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_baseRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_initReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"_lastStakedTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_lastUpdateTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_periodFinish","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_playbook","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_poolRewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_pros","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_punishTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_rewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_rewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_rewardRateList","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"_rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_startTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_teamRewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_teamWallet","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"_userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"base_","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"base_Rate_Reward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositToken","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"tokenID","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"accountAddr","type":"address"}],"name":"getAccountTotalUsdValue","outputs":[{"internalType":"int256","name":"usdValue","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getActiveAccounts","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getBalances","outputs":[{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"int256[]","name":"balances","type":"int256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"coinIndex","type":"uint256"}],"name":"getCoinAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getCoinLength","outputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getMarketState","outputs":[{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"int256[]","name":"deposits","type":"int256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"getReward","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"getTokenState","outputs":[{"internalType":"int256","name":"deposits","type":"int256"},{"internalType":"int256","name":"loans","type":"int256"},{"internalType":"int256","name":"collateral","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"one_Rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rate_forReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"tokenID","type":"address"}],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"sec_Rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"setAllpool","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"playbook","type":"address"}],"name":"setPlaybook","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"one","type":"uint256"},{"internalType":"uint256","name":"sec","type":"uint256"},{"internalType":"uint256","name":"thr","type":"uint256"},{"internalType":"uint256","name":"total","type":"uint256"}],"name":"setRate_Reward","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenaddress","type":"address"}],"name":"setTeamToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"eth","type":"address"},{"internalType":"address","name":"usdt","type":"address"},{"internalType":"address","name":"pros","type":"address"}],"name":"set_tokens","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"}],"name":"setprosToken","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"startTime","type":"uint256"}],"name":"startReward","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"thr_Rate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"tokenBalanceOf","outputs":[{"internalType":"int256","name":"amount","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"tokenBalanceOf","outputs":[{"internalType":"int256","name":"amount","type":"int256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawToken","outputs":[],"payable":true,"stateMutability":"payable","type":"function"}]