├── README.md ├── 1PoolConvert.sol ├── 1PoolStaking.sol ├── 1Pool.sol └── RewardPool.sol /README.md: -------------------------------------------------------------------------------- 1 | # Strategy-on-Binance-Smart-Chain 2 | 1Pool Yield aggregator smart contracts on Binance Smart Chain 3 | -------------------------------------------------------------------------------- /1PoolConvert.sol: -------------------------------------------------------------------------------- 1 | /** 2 | *Submitted for verification at BscScan.com on 2021-06-05 3 | */ 4 | 5 | // File: @openzeppelin/contracts/token/ERC20/IERC20.sol 6 | 7 | // SPDX-License-Identifier: MIT 8 | 9 | pragma solidity ^0.6.0; 10 | 11 | /** 12 | * @dev Interface of the ERC20 standard as defined in the EIP. 13 | */ 14 | interface IERC20 { 15 | /** 16 | * @dev Returns the amount of tokens in existence. 17 | */ 18 | function totalSupply() external view returns (uint256); 19 | 20 | /** 21 | * @dev Returns the amount of tokens owned by `account`. 22 | */ 23 | function balanceOf(address account) external view returns (uint256); 24 | 25 | /** 26 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 27 | * 28 | * Returns a boolean value indicating whether the operation succeeded. 29 | * 30 | * Emits a {Transfer} event. 31 | */ 32 | function transfer(address recipient, uint256 amount) external returns (bool); 33 | 34 | /** 35 | * @dev Returns the remaining number of tokens that `spender` will be 36 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 37 | * zero by default. 38 | * 39 | * This value changes when {approve} or {transferFrom} are called. 40 | */ 41 | function allowance(address owner, address spender) external view returns (uint256); 42 | 43 | /** 44 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 45 | * 46 | * Returns a boolean value indicating whether the operation succeeded. 47 | * 48 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 49 | * that someone may use both the old and the new allowance by unfortunate 50 | * transaction ordering. One possible solution to mitigate this race 51 | * condition is to first reduce the spender's allowance to 0 and set the 52 | * desired value afterwards: 53 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 54 | * 55 | * Emits an {Approval} event. 56 | */ 57 | function approve(address spender, uint256 amount) external returns (bool); 58 | 59 | /** 60 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 61 | * allowance mechanism. `amount` is then deducted from the caller's 62 | * allowance. 63 | * 64 | * Returns a boolean value indicating whether the operation succeeded. 65 | * 66 | * Emits a {Transfer} event. 67 | */ 68 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 69 | 70 | /** 71 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 72 | * another (`to`). 73 | * 74 | * Note that `value` may be zero. 75 | */ 76 | event Transfer(address indexed from, address indexed to, uint256 value); 77 | 78 | /** 79 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 80 | * a call to {approve}. `value` is the new allowance. 81 | */ 82 | event Approval(address indexed owner, address indexed spender, uint256 value); 83 | } 84 | 85 | // File: @openzeppelin/contracts/math/SafeMath.sol 86 | 87 | 88 | 89 | pragma solidity ^0.6.0; 90 | 91 | /** 92 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 93 | * checks. 94 | * 95 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 96 | * in bugs, because programmers usually assume that an overflow raises an 97 | * error, which is the standard behavior in high level programming languages. 98 | * `SafeMath` restores this intuition by reverting the transaction when an 99 | * operation overflows. 100 | * 101 | * Using this library instead of the unchecked operations eliminates an entire 102 | * class of bugs, so it's recommended to use it always. 103 | */ 104 | library SafeMath { 105 | /** 106 | * @dev Returns the addition of two unsigned integers, reverting on 107 | * overflow. 108 | * 109 | * Counterpart to Solidity's `+` operator. 110 | * 111 | * Requirements: 112 | * 113 | * - Addition cannot overflow. 114 | */ 115 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 116 | uint256 c = a + b; 117 | require(c >= a, "SafeMath: addition overflow"); 118 | 119 | return c; 120 | } 121 | 122 | /** 123 | * @dev Returns the subtraction of two unsigned integers, reverting on 124 | * overflow (when the result is negative). 125 | * 126 | * Counterpart to Solidity's `-` operator. 127 | * 128 | * Requirements: 129 | * 130 | * - Subtraction cannot overflow. 131 | */ 132 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 133 | return sub(a, b, "SafeMath: subtraction overflow"); 134 | } 135 | 136 | /** 137 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 138 | * overflow (when the result is negative). 139 | * 140 | * Counterpart to Solidity's `-` operator. 141 | * 142 | * Requirements: 143 | * 144 | * - Subtraction cannot overflow. 145 | */ 146 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 147 | require(b <= a, errorMessage); 148 | uint256 c = a - b; 149 | 150 | return c; 151 | } 152 | 153 | /** 154 | * @dev Returns the multiplication of two unsigned integers, reverting on 155 | * overflow. 156 | * 157 | * Counterpart to Solidity's `*` operator. 158 | * 159 | * Requirements: 160 | * 161 | * - Multiplication cannot overflow. 162 | */ 163 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 164 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 165 | // benefit is lost if 'b' is also tested. 166 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 167 | if (a == 0) { 168 | return 0; 169 | } 170 | 171 | uint256 c = a * b; 172 | require(c / a == b, "SafeMath: multiplication overflow"); 173 | 174 | return c; 175 | } 176 | 177 | /** 178 | * @dev Returns the integer division of two unsigned integers. Reverts on 179 | * division by zero. The result is rounded towards zero. 180 | * 181 | * Counterpart to Solidity's `/` operator. Note: this function uses a 182 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 183 | * uses an invalid opcode to revert (consuming all remaining gas). 184 | * 185 | * Requirements: 186 | * 187 | * - The divisor cannot be zero. 188 | */ 189 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 190 | return div(a, b, "SafeMath: division by zero"); 191 | } 192 | 193 | /** 194 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 195 | * division by zero. The result is rounded towards zero. 196 | * 197 | * Counterpart to Solidity's `/` operator. Note: this function uses a 198 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 199 | * uses an invalid opcode to revert (consuming all remaining gas). 200 | * 201 | * Requirements: 202 | * 203 | * - The divisor cannot be zero. 204 | */ 205 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 206 | require(b > 0, errorMessage); 207 | uint256 c = a / b; 208 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 209 | 210 | return c; 211 | } 212 | 213 | /** 214 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 215 | * Reverts when dividing by zero. 216 | * 217 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 218 | * opcode (which leaves remaining gas untouched) while Solidity uses an 219 | * invalid opcode to revert (consuming all remaining gas). 220 | * 221 | * Requirements: 222 | * 223 | * - The divisor cannot be zero. 224 | */ 225 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 226 | return mod(a, b, "SafeMath: modulo by zero"); 227 | } 228 | 229 | /** 230 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 231 | * Reverts with custom message when dividing by zero. 232 | * 233 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 234 | * opcode (which leaves remaining gas untouched) while Solidity uses an 235 | * invalid opcode to revert (consuming all remaining gas). 236 | * 237 | * Requirements: 238 | * 239 | * - The divisor cannot be zero. 240 | */ 241 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 242 | require(b != 0, errorMessage); 243 | return a % b; 244 | } 245 | } 246 | 247 | // File: @openzeppelin/contracts/utils/Address.sol 248 | 249 | 250 | 251 | pragma solidity ^0.6.2; 252 | 253 | /** 254 | * @dev Collection of functions related to the address type 255 | */ 256 | library Address { 257 | /** 258 | * @dev Returns true if `account` is a contract. 259 | * 260 | * [IMPORTANT] 261 | * ==== 262 | * It is unsafe to assume that an address for which this function returns 263 | * false is an externally-owned account (EOA) and not a contract. 264 | * 265 | * Among others, `isContract` will return false for the following 266 | * types of addresses: 267 | * 268 | * - an externally-owned account 269 | * - a contract in construction 270 | * - an address where a contract will be created 271 | * - an address where a contract lived, but was destroyed 272 | * ==== 273 | */ 274 | function isContract(address account) internal view returns (bool) { 275 | // This method relies in extcodesize, which returns 0 for contracts in 276 | // construction, since the code is only stored at the end of the 277 | // constructor execution. 278 | 279 | uint256 size; 280 | // solhint-disable-next-line no-inline-assembly 281 | assembly { size := extcodesize(account) } 282 | return size > 0; 283 | } 284 | 285 | /** 286 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 287 | * `recipient`, forwarding all available gas and reverting on errors. 288 | * 289 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 290 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 291 | * imposed by `transfer`, making them unable to receive funds via 292 | * `transfer`. {sendValue} removes this limitation. 293 | * 294 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 295 | * 296 | * IMPORTANT: because control is transferred to `recipient`, care must be 297 | * taken to not create reentrancy vulnerabilities. Consider using 298 | * {ReentrancyGuard} or the 299 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 300 | */ 301 | function sendValue(address payable recipient, uint256 amount) internal { 302 | require(address(this).balance >= amount, "Address: insufficient balance"); 303 | 304 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 305 | (bool success, ) = recipient.call{ value: amount }(""); 306 | require(success, "Address: unable to send value, recipient may have reverted"); 307 | } 308 | 309 | /** 310 | * @dev Performs a Solidity function call using a low level `call`. A 311 | * plain`call` is an unsafe replacement for a function call: use this 312 | * function instead. 313 | * 314 | * If `target` reverts with a revert reason, it is bubbled up by this 315 | * function (like regular Solidity function calls). 316 | * 317 | * Returns the raw returned data. To convert to the expected return value, 318 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 319 | * 320 | * Requirements: 321 | * 322 | * - `target` must be a contract. 323 | * - calling `target` with `data` must not revert. 324 | * 325 | * _Available since v3.1._ 326 | */ 327 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 328 | return functionCall(target, data, "Address: low-level call failed"); 329 | } 330 | 331 | /** 332 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 333 | * `errorMessage` as a fallback revert reason when `target` reverts. 334 | * 335 | * _Available since v3.1._ 336 | */ 337 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 338 | return _functionCallWithValue(target, data, 0, errorMessage); 339 | } 340 | 341 | /** 342 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 343 | * but also transferring `value` wei to `target`. 344 | * 345 | * Requirements: 346 | * 347 | * - the calling contract must have an ETH balance of at least `value`. 348 | * - the called Solidity function must be `payable`. 349 | * 350 | * _Available since v3.1._ 351 | */ 352 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 353 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 354 | } 355 | 356 | /** 357 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 358 | * with `errorMessage` as a fallback revert reason when `target` reverts. 359 | * 360 | * _Available since v3.1._ 361 | */ 362 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 363 | require(address(this).balance >= value, "Address: insufficient balance for call"); 364 | return _functionCallWithValue(target, data, value, errorMessage); 365 | } 366 | 367 | function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { 368 | require(isContract(target), "Address: call to non-contract"); 369 | 370 | // solhint-disable-next-line avoid-low-level-calls 371 | (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); 372 | if (success) { 373 | return returndata; 374 | } else { 375 | // Look for revert reason and bubble it up if present 376 | if (returndata.length > 0) { 377 | // The easiest way to bubble the revert reason is using memory via assembly 378 | 379 | // solhint-disable-next-line no-inline-assembly 380 | assembly { 381 | let returndata_size := mload(returndata) 382 | revert(add(32, returndata), returndata_size) 383 | } 384 | } else { 385 | revert(errorMessage); 386 | } 387 | } 388 | } 389 | } 390 | 391 | // File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol 392 | 393 | 394 | 395 | pragma solidity ^0.6.0; 396 | 397 | 398 | 399 | 400 | /** 401 | * @title SafeERC20 402 | * @dev Wrappers around ERC20 operations that throw on failure (when the token 403 | * contract returns false). Tokens that return no value (and instead revert or 404 | * throw on failure) are also supported, non-reverting calls are assumed to be 405 | * successful. 406 | * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, 407 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 408 | */ 409 | library SafeERC20 { 410 | using SafeMath for uint256; 411 | using Address for address; 412 | 413 | function safeTransfer(IERC20 token, address to, uint256 value) internal { 414 | _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 415 | } 416 | 417 | function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { 418 | _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 419 | } 420 | 421 | /** 422 | * @dev Deprecated. This function has issues similar to the ones found in 423 | * {IERC20-approve}, and its usage is discouraged. 424 | * 425 | * Whenever possible, use {safeIncreaseAllowance} and 426 | * {safeDecreaseAllowance} instead. 427 | */ 428 | function safeApprove(IERC20 token, address spender, uint256 value) internal { 429 | // safeApprove should only be called when setting an initial allowance, 430 | // or when resetting it to zero. To increase and decrease it, use 431 | // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' 432 | // solhint-disable-next-line max-line-length 433 | require((value == 0) || (token.allowance(address(this), spender) == 0), 434 | "SafeERC20: approve from non-zero to non-zero allowance" 435 | ); 436 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 437 | } 438 | 439 | function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { 440 | uint256 newAllowance = token.allowance(address(this), spender).add(value); 441 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 442 | } 443 | 444 | function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { 445 | uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); 446 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 447 | } 448 | 449 | /** 450 | * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement 451 | * on the return value: the return value is optional (but if data is returned, it must not be false). 452 | * @param token The token targeted by the call. 453 | * @param data The call data (encoded using abi.encode or one of its variants). 454 | */ 455 | function _callOptionalReturn(IERC20 token, bytes memory data) private { 456 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since 457 | // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that 458 | // the target address contains contract code and also asserts for success in the low-level call. 459 | 460 | bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); 461 | if (returndata.length > 0) { // Return data is optional 462 | // solhint-disable-next-line max-line-length 463 | require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); 464 | } 465 | } 466 | } 467 | 468 | // File: contracts/uniswapv2/interfaces/IUniswapV2ERC20.sol 469 | 470 | pragma solidity >=0.5.0; 471 | 472 | interface IUniswapV2ERC20 { 473 | event Approval(address indexed owner, address indexed spender, uint value); 474 | event Transfer(address indexed from, address indexed to, uint value); 475 | 476 | function name() external pure returns (string memory); 477 | function symbol() external pure returns (string memory); 478 | function decimals() external pure returns (uint8); 479 | function totalSupply() external view returns (uint); 480 | function balanceOf(address owner) external view returns (uint); 481 | function allowance(address owner, address spender) external view returns (uint); 482 | 483 | function approve(address spender, uint value) external returns (bool); 484 | function transfer(address to, uint value) external returns (bool); 485 | function transferFrom(address from, address to, uint value) external returns (bool); 486 | 487 | function DOMAIN_SEPARATOR() external view returns (bytes32); 488 | function PERMIT_TYPEHASH() external pure returns (bytes32); 489 | function nonces(address owner) external view returns (uint); 490 | 491 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 492 | } 493 | 494 | // File: contracts/uniswapv2/interfaces/IUniswapV2Pair.sol 495 | 496 | pragma solidity >=0.5.0; 497 | 498 | interface IUniswapV2Pair { 499 | event Approval(address indexed owner, address indexed spender, uint value); 500 | event Transfer(address indexed from, address indexed to, uint value); 501 | 502 | function name() external pure returns (string memory); 503 | function symbol() external pure returns (string memory); 504 | function decimals() external pure returns (uint8); 505 | function totalSupply() external view returns (uint); 506 | function balanceOf(address owner) external view returns (uint); 507 | function allowance(address owner, address spender) external view returns (uint); 508 | 509 | function approve(address spender, uint value) external returns (bool); 510 | function transfer(address to, uint value) external returns (bool); 511 | function transferFrom(address from, address to, uint value) external returns (bool); 512 | 513 | function DOMAIN_SEPARATOR() external view returns (bytes32); 514 | function PERMIT_TYPEHASH() external pure returns (bytes32); 515 | function nonces(address owner) external view returns (uint); 516 | 517 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 518 | 519 | event Mint(address indexed sender, uint amount0, uint amount1); 520 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); 521 | event Swap( 522 | address indexed sender, 523 | uint amount0In, 524 | uint amount1In, 525 | uint amount0Out, 526 | uint amount1Out, 527 | address indexed to 528 | ); 529 | event Sync(uint112 reserve0, uint112 reserve1); 530 | 531 | function MINIMUM_LIQUIDITY() external pure returns (uint); 532 | function factory() external view returns (address); 533 | function token0() external view returns (address); 534 | function token1() external view returns (address); 535 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 536 | function price0CumulativeLast() external view returns (uint); 537 | function price1CumulativeLast() external view returns (uint); 538 | function kLast() external view returns (uint); 539 | 540 | function mint(address to) external returns (uint liquidity); 541 | function burn(address to) external returns (uint amount0, uint amount1); 542 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; 543 | function skim(address to) external; 544 | function sync() external; 545 | 546 | function initialize(address, address) external; 547 | } 548 | 549 | // File: contracts/uniswapv2/interfaces/IUniswapV2Factory.sol 550 | 551 | pragma solidity >=0.5.0; 552 | 553 | interface IUniswapV2Factory { 554 | event PairCreated(address indexed token0, address indexed token1, address pair, uint); 555 | 556 | function feeTo() external view returns (address); 557 | function feeToSetter() external view returns (address); 558 | function migrator() external view returns (address); 559 | 560 | function getPair(address tokenA, address tokenB) external view returns (address pair); 561 | function allPairs(uint) external view returns (address pair); 562 | function allPairsLength() external view returns (uint); 563 | 564 | function createPair(address tokenA, address tokenB) external returns (address pair); 565 | 566 | function setFeeTo(address) external; 567 | function setFeeToSetter(address) external; 568 | function setMigrator(address) external; 569 | } 570 | 571 | // File: contracts/OnePoolConvert.sol 572 | 573 | pragma solidity 0.6.12; 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | contract OnePoolConvert { 583 | using SafeMath for uint256; 584 | using SafeERC20 for IERC20; 585 | 586 | IUniswapV2Factory public factory; 587 | address public stake; 588 | address public sushi; 589 | address public onePool; 590 | 591 | constructor(IUniswapV2Factory _factory, address _stake, address _sushi, address _onePool) public { 592 | factory = _factory; 593 | sushi = _sushi; 594 | stake = _stake; 595 | onePool = _onePool; 596 | } 597 | 598 | function convert() public { 599 | uint256 _onePoolAmount = IERC20(onePool).balanceOf(address(this)); 600 | require(msg.sender == tx.origin, "do not convert from contract"); 601 | _safeTransfer(onePool, factory.getPair(onePool, sushi), _onePoolAmount); 602 | _toOnePool(_onePoolAmount); 603 | } 604 | 605 | 606 | function _toOnePool(uint256 amountIn) internal { 607 | IUniswapV2Pair pair = IUniswapV2Pair(factory.getPair(onePool, sushi)); 608 | (uint reserve0, uint reserve1,) = pair.getReserves(); 609 | address token0 = pair.token0(); 610 | (uint reserveIn, uint reserveOut) = token0 == onePool ? (reserve0, reserve1) : (reserve1, reserve0); 611 | uint amountInWithFee = amountIn.mul(997); 612 | uint numerator = amountInWithFee.mul(reserveOut); 613 | uint denominator = reserveIn.mul(1000).add(amountInWithFee); 614 | uint amountOut = numerator / denominator; 615 | (uint amount0Out, uint amount1Out) = token0 == onePool ? (uint(0), amountOut) : (amountOut, uint(0)); 616 | pair.swap(amount0Out, amount1Out, stake, new bytes(0)); 617 | } 618 | 619 | function _safeTransfer(address token, address to, uint256 amount) internal { 620 | IERC20(token).safeTransfer(to, amount); 621 | } 622 | } 623 | -------------------------------------------------------------------------------- /1PoolStaking.sol: -------------------------------------------------------------------------------- 1 | /** 2 | *Submitted for verification at BscScan.com on 2021-06-05 3 | */ 4 | 5 | // File: @openzeppelin/contracts/token/ERC20/IERC20.sol 6 | 7 | // SPDX-License-Identifier: MIT 8 | 9 | pragma solidity ^0.6.0; 10 | 11 | /** 12 | * @dev Interface of the ERC20 standard as defined in the EIP. 13 | */ 14 | interface IERC20 { 15 | /** 16 | * @dev Returns the amount of tokens in existence. 17 | */ 18 | function totalSupply() external view returns (uint256); 19 | 20 | /** 21 | * @dev Returns the amount of tokens owned by `account`. 22 | */ 23 | function balanceOf(address account) external view returns (uint256); 24 | 25 | /** 26 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 27 | * 28 | * Returns a boolean value indicating whether the operation succeeded. 29 | * 30 | * Emits a {Transfer} event. 31 | */ 32 | function transfer(address recipient, uint256 amount) external returns (bool); 33 | 34 | /** 35 | * @dev Returns the remaining number of tokens that `spender` will be 36 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 37 | * zero by default. 38 | * 39 | * This value changes when {approve} or {transferFrom} are called. 40 | */ 41 | function allowance(address owner, address spender) external view returns (uint256); 42 | 43 | /** 44 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 45 | * 46 | * Returns a boolean value indicating whether the operation succeeded. 47 | * 48 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 49 | * that someone may use both the old and the new allowance by unfortunate 50 | * transaction ordering. One possible solution to mitigate this race 51 | * condition is to first reduce the spender's allowance to 0 and set the 52 | * desired value afterwards: 53 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 54 | * 55 | * Emits an {Approval} event. 56 | */ 57 | function approve(address spender, uint256 amount) external returns (bool); 58 | 59 | /** 60 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 61 | * allowance mechanism. `amount` is then deducted from the caller's 62 | * allowance. 63 | * 64 | * Returns a boolean value indicating whether the operation succeeded. 65 | * 66 | * Emits a {Transfer} event. 67 | */ 68 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 69 | 70 | /** 71 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 72 | * another (`to`). 73 | * 74 | * Note that `value` may be zero. 75 | */ 76 | event Transfer(address indexed from, address indexed to, uint256 value); 77 | 78 | /** 79 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 80 | * a call to {approve}. `value` is the new allowance. 81 | */ 82 | event Approval(address indexed owner, address indexed spender, uint256 value); 83 | } 84 | 85 | // File: @openzeppelin/contracts/GSN/Context.sol 86 | 87 | 88 | 89 | pragma solidity ^0.6.0; 90 | 91 | /* 92 | * @dev Provides information about the current execution context, including the 93 | * sender of the transaction and its data. While these are generally available 94 | * via msg.sender and msg.data, they should not be accessed in such a direct 95 | * manner, since when dealing with GSN meta-transactions the account sending and 96 | * paying for execution may not be the actual sender (as far as an application 97 | * is concerned). 98 | * 99 | * This contract is only required for intermediate, library-like contracts. 100 | */ 101 | abstract contract Context { 102 | function _msgSender() internal view virtual returns (address payable) { 103 | return msg.sender; 104 | } 105 | 106 | function _msgData() internal view virtual returns (bytes memory) { 107 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 108 | return msg.data; 109 | } 110 | } 111 | 112 | // File: @openzeppelin/contracts/math/SafeMath.sol 113 | 114 | 115 | 116 | pragma solidity ^0.6.0; 117 | 118 | /** 119 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 120 | * checks. 121 | * 122 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 123 | * in bugs, because programmers usually assume that an overflow raises an 124 | * error, which is the standard behavior in high level programming languages. 125 | * `SafeMath` restores this intuition by reverting the transaction when an 126 | * operation overflows. 127 | * 128 | * Using this library instead of the unchecked operations eliminates an entire 129 | * class of bugs, so it's recommended to use it always. 130 | */ 131 | library SafeMath { 132 | /** 133 | * @dev Returns the addition of two unsigned integers, reverting on 134 | * overflow. 135 | * 136 | * Counterpart to Solidity's `+` operator. 137 | * 138 | * Requirements: 139 | * 140 | * - Addition cannot overflow. 141 | */ 142 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 143 | uint256 c = a + b; 144 | require(c >= a, "SafeMath: addition overflow"); 145 | 146 | return c; 147 | } 148 | 149 | /** 150 | * @dev Returns the subtraction of two unsigned integers, reverting on 151 | * overflow (when the result is negative). 152 | * 153 | * Counterpart to Solidity's `-` operator. 154 | * 155 | * Requirements: 156 | * 157 | * - Subtraction cannot overflow. 158 | */ 159 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 160 | return sub(a, b, "SafeMath: subtraction overflow"); 161 | } 162 | 163 | /** 164 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 165 | * overflow (when the result is negative). 166 | * 167 | * Counterpart to Solidity's `-` operator. 168 | * 169 | * Requirements: 170 | * 171 | * - Subtraction cannot overflow. 172 | */ 173 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 174 | require(b <= a, errorMessage); 175 | uint256 c = a - b; 176 | 177 | return c; 178 | } 179 | 180 | /** 181 | * @dev Returns the multiplication of two unsigned integers, reverting on 182 | * overflow. 183 | * 184 | * Counterpart to Solidity's `*` operator. 185 | * 186 | * Requirements: 187 | * 188 | * - Multiplication cannot overflow. 189 | */ 190 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 191 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 192 | // benefit is lost if 'b' is also tested. 193 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 194 | if (a == 0) { 195 | return 0; 196 | } 197 | 198 | uint256 c = a * b; 199 | require(c / a == b, "SafeMath: multiplication overflow"); 200 | 201 | return c; 202 | } 203 | 204 | /** 205 | * @dev Returns the integer division of two unsigned integers. Reverts on 206 | * division by zero. The result is rounded towards zero. 207 | * 208 | * Counterpart to Solidity's `/` operator. Note: this function uses a 209 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 210 | * uses an invalid opcode to revert (consuming all remaining gas). 211 | * 212 | * Requirements: 213 | * 214 | * - The divisor cannot be zero. 215 | */ 216 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 217 | return div(a, b, "SafeMath: division by zero"); 218 | } 219 | 220 | /** 221 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 222 | * division by zero. The result is rounded towards zero. 223 | * 224 | * Counterpart to Solidity's `/` operator. Note: this function uses a 225 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 226 | * uses an invalid opcode to revert (consuming all remaining gas). 227 | * 228 | * Requirements: 229 | * 230 | * - The divisor cannot be zero. 231 | */ 232 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 233 | require(b > 0, errorMessage); 234 | uint256 c = a / b; 235 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 236 | 237 | return c; 238 | } 239 | 240 | /** 241 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 242 | * Reverts when dividing by zero. 243 | * 244 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 245 | * opcode (which leaves remaining gas untouched) while Solidity uses an 246 | * invalid opcode to revert (consuming all remaining gas). 247 | * 248 | * Requirements: 249 | * 250 | * - The divisor cannot be zero. 251 | */ 252 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 253 | return mod(a, b, "SafeMath: modulo by zero"); 254 | } 255 | 256 | /** 257 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 258 | * Reverts with custom message when dividing by zero. 259 | * 260 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 261 | * opcode (which leaves remaining gas untouched) while Solidity uses an 262 | * invalid opcode to revert (consuming all remaining gas). 263 | * 264 | * Requirements: 265 | * 266 | * - The divisor cannot be zero. 267 | */ 268 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 269 | require(b != 0, errorMessage); 270 | return a % b; 271 | } 272 | } 273 | 274 | // File: @openzeppelin/contracts/utils/Address.sol 275 | 276 | 277 | 278 | pragma solidity ^0.6.2; 279 | 280 | /** 281 | * @dev Collection of functions related to the address type 282 | */ 283 | library Address { 284 | /** 285 | * @dev Returns true if `account` is a contract. 286 | * 287 | * [IMPORTANT] 288 | * ==== 289 | * It is unsafe to assume that an address for which this function returns 290 | * false is an externally-owned account (EOA) and not a contract. 291 | * 292 | * Among others, `isContract` will return false for the following 293 | * types of addresses: 294 | * 295 | * - an externally-owned account 296 | * - a contract in construction 297 | * - an address where a contract will be created 298 | * - an address where a contract lived, but was destroyed 299 | * ==== 300 | */ 301 | function isContract(address account) internal view returns (bool) { 302 | // This method relies in extcodesize, which returns 0 for contracts in 303 | // construction, since the code is only stored at the end of the 304 | // constructor execution. 305 | 306 | uint256 size; 307 | // solhint-disable-next-line no-inline-assembly 308 | assembly { size := extcodesize(account) } 309 | return size > 0; 310 | } 311 | 312 | /** 313 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 314 | * `recipient`, forwarding all available gas and reverting on errors. 315 | * 316 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 317 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 318 | * imposed by `transfer`, making them unable to receive funds via 319 | * `transfer`. {sendValue} removes this limitation. 320 | * 321 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 322 | * 323 | * IMPORTANT: because control is transferred to `recipient`, care must be 324 | * taken to not create reentrancy vulnerabilities. Consider using 325 | * {ReentrancyGuard} or the 326 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 327 | */ 328 | function sendValue(address payable recipient, uint256 amount) internal { 329 | require(address(this).balance >= amount, "Address: insufficient balance"); 330 | 331 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 332 | (bool success, ) = recipient.call{ value: amount }(""); 333 | require(success, "Address: unable to send value, recipient may have reverted"); 334 | } 335 | 336 | /** 337 | * @dev Performs a Solidity function call using a low level `call`. A 338 | * plain`call` is an unsafe replacement for a function call: use this 339 | * function instead. 340 | * 341 | * If `target` reverts with a revert reason, it is bubbled up by this 342 | * function (like regular Solidity function calls). 343 | * 344 | * Returns the raw returned data. To convert to the expected return value, 345 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 346 | * 347 | * Requirements: 348 | * 349 | * - `target` must be a contract. 350 | * - calling `target` with `data` must not revert. 351 | * 352 | * _Available since v3.1._ 353 | */ 354 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 355 | return functionCall(target, data, "Address: low-level call failed"); 356 | } 357 | 358 | /** 359 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 360 | * `errorMessage` as a fallback revert reason when `target` reverts. 361 | * 362 | * _Available since v3.1._ 363 | */ 364 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 365 | return _functionCallWithValue(target, data, 0, errorMessage); 366 | } 367 | 368 | /** 369 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 370 | * but also transferring `value` wei to `target`. 371 | * 372 | * Requirements: 373 | * 374 | * - the calling contract must have an ETH balance of at least `value`. 375 | * - the called Solidity function must be `payable`. 376 | * 377 | * _Available since v3.1._ 378 | */ 379 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 380 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 381 | } 382 | 383 | /** 384 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 385 | * with `errorMessage` as a fallback revert reason when `target` reverts. 386 | * 387 | * _Available since v3.1._ 388 | */ 389 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 390 | require(address(this).balance >= value, "Address: insufficient balance for call"); 391 | return _functionCallWithValue(target, data, value, errorMessage); 392 | } 393 | 394 | function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { 395 | require(isContract(target), "Address: call to non-contract"); 396 | 397 | // solhint-disable-next-line avoid-low-level-calls 398 | (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); 399 | if (success) { 400 | return returndata; 401 | } else { 402 | // Look for revert reason and bubble it up if present 403 | if (returndata.length > 0) { 404 | // The easiest way to bubble the revert reason is using memory via assembly 405 | 406 | // solhint-disable-next-line no-inline-assembly 407 | assembly { 408 | let returndata_size := mload(returndata) 409 | revert(add(32, returndata), returndata_size) 410 | } 411 | } else { 412 | revert(errorMessage); 413 | } 414 | } 415 | } 416 | } 417 | 418 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 419 | 420 | 421 | 422 | pragma solidity ^0.6.0; 423 | 424 | 425 | 426 | 427 | 428 | /** 429 | * @dev Implementation of the {IERC20} interface. 430 | * 431 | * This implementation is agnostic to the way tokens are created. This means 432 | * that a supply mechanism has to be added in a derived contract using {_mint}. 433 | * For a generic mechanism see {ERC20PresetMinterPauser}. 434 | * 435 | * TIP: For a detailed writeup see our guide 436 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 437 | * to implement supply mechanisms]. 438 | * 439 | * We have followed general OpenZeppelin guidelines: functions revert instead 440 | * of returning `false` on failure. This behavior is nonetheless conventional 441 | * and does not conflict with the expectations of ERC20 applications. 442 | * 443 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 444 | * This allows applications to reconstruct the allowance for all accounts just 445 | * by listening to said events. Other implementations of the EIP may not emit 446 | * these events, as it isn't required by the specification. 447 | * 448 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 449 | * functions have been added to mitigate the well-known issues around setting 450 | * allowances. See {IERC20-approve}. 451 | */ 452 | contract ERC20 is Context, IERC20 { 453 | using SafeMath for uint256; 454 | using Address for address; 455 | 456 | mapping (address => uint256) private _balances; 457 | 458 | mapping (address => mapping (address => uint256)) private _allowances; 459 | 460 | uint256 private _totalSupply; 461 | 462 | string private _name; 463 | string private _symbol; 464 | uint8 private _decimals; 465 | 466 | /** 467 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 468 | * a default value of 18. 469 | * 470 | * To select a different value for {decimals}, use {_setupDecimals}. 471 | * 472 | * All three of these values are immutable: they can only be set once during 473 | * construction. 474 | */ 475 | constructor (string memory name, string memory symbol) public { 476 | _name = name; 477 | _symbol = symbol; 478 | _decimals = 18; 479 | } 480 | 481 | /** 482 | * @dev Returns the name of the token. 483 | */ 484 | function name() public view returns (string memory) { 485 | return _name; 486 | } 487 | 488 | /** 489 | * @dev Returns the symbol of the token, usually a shorter version of the 490 | * name. 491 | */ 492 | function symbol() public view returns (string memory) { 493 | return _symbol; 494 | } 495 | 496 | /** 497 | * @dev Returns the number of decimals used to get its user representation. 498 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 499 | * be displayed to a user as `5,05` (`505 / 10 ** 2`). 500 | * 501 | * Tokens usually opt for a value of 18, imitating the relationship between 502 | * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is 503 | * called. 504 | * 505 | * NOTE: This information is only used for _display_ purposes: it in 506 | * no way affects any of the arithmetic of the contract, including 507 | * {IERC20-balanceOf} and {IERC20-transfer}. 508 | */ 509 | function decimals() public view returns (uint8) { 510 | return _decimals; 511 | } 512 | 513 | /** 514 | * @dev See {IERC20-totalSupply}. 515 | */ 516 | function totalSupply() public view override returns (uint256) { 517 | return _totalSupply; 518 | } 519 | 520 | /** 521 | * @dev See {IERC20-balanceOf}. 522 | */ 523 | function balanceOf(address account) public view override returns (uint256) { 524 | return _balances[account]; 525 | } 526 | 527 | /** 528 | * @dev See {IERC20-transfer}. 529 | * 530 | * Requirements: 531 | * 532 | * - `recipient` cannot be the zero address. 533 | * - the caller must have a balance of at least `amount`. 534 | */ 535 | function transfer(address recipient, uint256 amount) public virtual override returns (bool) { 536 | _transfer(_msgSender(), recipient, amount); 537 | return true; 538 | } 539 | 540 | /** 541 | * @dev See {IERC20-allowance}. 542 | */ 543 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 544 | return _allowances[owner][spender]; 545 | } 546 | 547 | /** 548 | * @dev See {IERC20-approve}. 549 | * 550 | * Requirements: 551 | * 552 | * - `spender` cannot be the zero address. 553 | */ 554 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 555 | _approve(_msgSender(), spender, amount); 556 | return true; 557 | } 558 | 559 | /** 560 | * @dev See {IERC20-transferFrom}. 561 | * 562 | * Emits an {Approval} event indicating the updated allowance. This is not 563 | * required by the EIP. See the note at the beginning of {ERC20}; 564 | * 565 | * Requirements: 566 | * - `sender` and `recipient` cannot be the zero address. 567 | * - `sender` must have a balance of at least `amount`. 568 | * - the caller must have allowance for ``sender``'s tokens of at least 569 | * `amount`. 570 | */ 571 | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { 572 | _transfer(sender, recipient, amount); 573 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 574 | return true; 575 | } 576 | 577 | /** 578 | * @dev Atomically increases the allowance granted to `spender` by the caller. 579 | * 580 | * This is an alternative to {approve} that can be used as a mitigation for 581 | * problems described in {IERC20-approve}. 582 | * 583 | * Emits an {Approval} event indicating the updated allowance. 584 | * 585 | * Requirements: 586 | * 587 | * - `spender` cannot be the zero address. 588 | */ 589 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 590 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 591 | return true; 592 | } 593 | 594 | /** 595 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 596 | * 597 | * This is an alternative to {approve} that can be used as a mitigation for 598 | * problems described in {IERC20-approve}. 599 | * 600 | * Emits an {Approval} event indicating the updated allowance. 601 | * 602 | * Requirements: 603 | * 604 | * - `spender` cannot be the zero address. 605 | * - `spender` must have allowance for the caller of at least 606 | * `subtractedValue`. 607 | */ 608 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 609 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 610 | return true; 611 | } 612 | 613 | /** 614 | * @dev Moves tokens `amount` from `sender` to `recipient`. 615 | * 616 | * This is internal function is equivalent to {transfer}, and can be used to 617 | * e.g. implement automatic token fees, slashing mechanisms, etc. 618 | * 619 | * Emits a {Transfer} event. 620 | * 621 | * Requirements: 622 | * 623 | * - `sender` cannot be the zero address. 624 | * - `recipient` cannot be the zero address. 625 | * - `sender` must have a balance of at least `amount`. 626 | */ 627 | function _transfer(address sender, address recipient, uint256 amount) internal virtual { 628 | require(sender != address(0), "ERC20: transfer from the zero address"); 629 | require(recipient != address(0), "ERC20: transfer to the zero address"); 630 | 631 | _beforeTokenTransfer(sender, recipient, amount); 632 | 633 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 634 | _balances[recipient] = _balances[recipient].add(amount); 635 | emit Transfer(sender, recipient, amount); 636 | } 637 | 638 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 639 | * the total supply. 640 | * 641 | * Emits a {Transfer} event with `from` set to the zero address. 642 | * 643 | * Requirements 644 | * 645 | * - `to` cannot be the zero address. 646 | */ 647 | function _mint(address account, uint256 amount) internal virtual { 648 | require(account != address(0), "ERC20: mint to the zero address"); 649 | 650 | _beforeTokenTransfer(address(0), account, amount); 651 | 652 | _totalSupply = _totalSupply.add(amount); 653 | _balances[account] = _balances[account].add(amount); 654 | emit Transfer(address(0), account, amount); 655 | } 656 | 657 | /** 658 | * @dev Destroys `amount` tokens from `account`, reducing the 659 | * total supply. 660 | * 661 | * Emits a {Transfer} event with `to` set to the zero address. 662 | * 663 | * Requirements 664 | * 665 | * - `account` cannot be the zero address. 666 | * - `account` must have at least `amount` tokens. 667 | */ 668 | function _burn(address account, uint256 amount) internal virtual { 669 | require(account != address(0), "ERC20: burn from the zero address"); 670 | 671 | _beforeTokenTransfer(account, address(0), amount); 672 | 673 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 674 | _totalSupply = _totalSupply.sub(amount); 675 | emit Transfer(account, address(0), amount); 676 | } 677 | 678 | /** 679 | * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. 680 | * 681 | * This internal function is equivalent to `approve`, and can be used to 682 | * e.g. set automatic allowances for certain subsystems, etc. 683 | * 684 | * Emits an {Approval} event. 685 | * 686 | * Requirements: 687 | * 688 | * - `owner` cannot be the zero address. 689 | * - `spender` cannot be the zero address. 690 | */ 691 | function _approve(address owner, address spender, uint256 amount) internal virtual { 692 | require(owner != address(0), "ERC20: approve from the zero address"); 693 | require(spender != address(0), "ERC20: approve to the zero address"); 694 | 695 | _allowances[owner][spender] = amount; 696 | emit Approval(owner, spender, amount); 697 | } 698 | 699 | /** 700 | * @dev Sets {decimals} to a value other than the default one of 18. 701 | * 702 | * WARNING: This function should only be called from the constructor. Most 703 | * applications that interact with token contracts will not expect 704 | * {decimals} to ever change, and may work incorrectly if it does. 705 | */ 706 | function _setupDecimals(uint8 decimals_) internal { 707 | _decimals = decimals_; 708 | } 709 | 710 | /** 711 | * @dev Hook that is called before any transfer of tokens. This includes 712 | * minting and burning. 713 | * 714 | * Calling conditions: 715 | * 716 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 717 | * will be to transferred to `to`. 718 | * - when `from` is zero, `amount` tokens will be minted for `to`. 719 | * - when `to` is zero, `amount` of ``from``'s tokens will be burned. 720 | * - `from` and `to` are never both zero. 721 | * 722 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 723 | */ 724 | function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } 725 | } 726 | 727 | // File: contracts/OnePoolStaking.sol 728 | 729 | pragma solidity 0.6.12; 730 | 731 | 732 | 733 | 734 | 735 | contract OnePoolStaking is ERC20("wrapped1Pool", "i1Pool"){ 736 | using SafeMath for uint256; 737 | IERC20 public onePool; 738 | 739 | constructor(IERC20 _onePool) public { 740 | onePool = _onePool; 741 | } 742 | 743 | // Pay some onePools. Earn some shares. 744 | function deposit(uint256 _amount) public { 745 | uint256 totalonePool = onePool.balanceOf(address(this)); 746 | uint256 totalShares = totalSupply(); 747 | if (totalShares == 0 || totalonePool == 0) { 748 | _mint(msg.sender, _amount); 749 | } else { 750 | uint256 what = _amount.mul(totalShares).div(totalonePool); 751 | _mint(msg.sender, what); 752 | } 753 | onePool.transferFrom(msg.sender, address(this), _amount); 754 | } 755 | 756 | // Claim back your onePools. 757 | function withdraw(uint256 _share) public { 758 | uint256 totalShares = totalSupply(); 759 | uint256 what = _share.mul(onePool.balanceOf(address(this))).div(totalShares); 760 | _burn(msg.sender, _share); 761 | onePool.transfer(msg.sender, what); 762 | } 763 | } 764 | -------------------------------------------------------------------------------- /1Pool.sol: -------------------------------------------------------------------------------- 1 | /** 2 | *Submitted for verification at BscScan.com on 2021-06-05 3 | */ 4 | 5 | // File: @openzeppelin/contracts/GSN/Context.sol 6 | 7 | // SPDX-License-Identifier: MIT 8 | 9 | pragma solidity ^0.6.0; 10 | 11 | /* 12 | * @dev Provides information about the current execution context, including the 13 | * sender of the transaction and its data. While these are generally available 14 | * via msg.sender and msg.data, they should not be accessed in such a direct 15 | * manner, since when dealing with GSN meta-transactions the account sending and 16 | * paying for execution may not be the actual sender (as far as an application 17 | * is concerned). 18 | * 19 | * This contract is only required for intermediate, library-like contracts. 20 | */ 21 | abstract contract Context { 22 | function _msgSender() internal view virtual returns (address payable) { 23 | return msg.sender; 24 | } 25 | 26 | function _msgData() internal view virtual returns (bytes memory) { 27 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 28 | return msg.data; 29 | } 30 | } 31 | 32 | // File: @openzeppelin/contracts/token/ERC20/IERC20.sol 33 | 34 | 35 | 36 | pragma solidity ^0.6.0; 37 | 38 | /** 39 | * @dev Interface of the ERC20 standard as defined in the EIP. 40 | */ 41 | interface IERC20 { 42 | /** 43 | * @dev Returns the amount of tokens in existence. 44 | */ 45 | function totalSupply() external view returns (uint256); 46 | 47 | /** 48 | * @dev Returns the amount of tokens owned by `account`. 49 | */ 50 | function balanceOf(address account) external view returns (uint256); 51 | 52 | /** 53 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 54 | * 55 | * Returns a boolean value indicating whether the operation succeeded. 56 | * 57 | * Emits a {Transfer} event. 58 | */ 59 | function transfer(address recipient, uint256 amount) external returns (bool); 60 | 61 | /** 62 | * @dev Returns the remaining number of tokens that `spender` will be 63 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 64 | * zero by default. 65 | * 66 | * This value changes when {approve} or {transferFrom} are called. 67 | */ 68 | function allowance(address owner, address spender) external view returns (uint256); 69 | 70 | /** 71 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 72 | * 73 | * Returns a boolean value indicating whether the operation succeeded. 74 | * 75 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 76 | * that someone may use both the old and the new allowance by unfortunate 77 | * transaction ordering. One possible solution to mitigate this race 78 | * condition is to first reduce the spender's allowance to 0 and set the 79 | * desired value afterwards: 80 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 81 | * 82 | * Emits an {Approval} event. 83 | */ 84 | function approve(address spender, uint256 amount) external returns (bool); 85 | 86 | /** 87 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 88 | * allowance mechanism. `amount` is then deducted from the caller's 89 | * allowance. 90 | * 91 | * Returns a boolean value indicating whether the operation succeeded. 92 | * 93 | * Emits a {Transfer} event. 94 | */ 95 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 96 | 97 | /** 98 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 99 | * another (`to`). 100 | * 101 | * Note that `value` may be zero. 102 | */ 103 | event Transfer(address indexed from, address indexed to, uint256 value); 104 | 105 | /** 106 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 107 | * a call to {approve}. `value` is the new allowance. 108 | */ 109 | event Approval(address indexed owner, address indexed spender, uint256 value); 110 | } 111 | 112 | // File: @openzeppelin/contracts/math/SafeMath.sol 113 | 114 | 115 | 116 | pragma solidity ^0.6.0; 117 | 118 | /** 119 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 120 | * checks. 121 | * 122 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 123 | * in bugs, because programmers usually assume that an overflow raises an 124 | * error, which is the standard behavior in high level programming languages. 125 | * `SafeMath` restores this intuition by reverting the transaction when an 126 | * operation overflows. 127 | * 128 | * Using this library instead of the unchecked operations eliminates an entire 129 | * class of bugs, so it's recommended to use it always. 130 | */ 131 | library SafeMath { 132 | /** 133 | * @dev Returns the addition of two unsigned integers, reverting on 134 | * overflow. 135 | * 136 | * Counterpart to Solidity's `+` operator. 137 | * 138 | * Requirements: 139 | * 140 | * - Addition cannot overflow. 141 | */ 142 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 143 | uint256 c = a + b; 144 | require(c >= a, "SafeMath: addition overflow"); 145 | 146 | return c; 147 | } 148 | 149 | /** 150 | * @dev Returns the subtraction of two unsigned integers, reverting on 151 | * overflow (when the result is negative). 152 | * 153 | * Counterpart to Solidity's `-` operator. 154 | * 155 | * Requirements: 156 | * 157 | * - Subtraction cannot overflow. 158 | */ 159 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 160 | return sub(a, b, "SafeMath: subtraction overflow"); 161 | } 162 | 163 | /** 164 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 165 | * overflow (when the result is negative). 166 | * 167 | * Counterpart to Solidity's `-` operator. 168 | * 169 | * Requirements: 170 | * 171 | * - Subtraction cannot overflow. 172 | */ 173 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 174 | require(b <= a, errorMessage); 175 | uint256 c = a - b; 176 | 177 | return c; 178 | } 179 | 180 | /** 181 | * @dev Returns the multiplication of two unsigned integers, reverting on 182 | * overflow. 183 | * 184 | * Counterpart to Solidity's `*` operator. 185 | * 186 | * Requirements: 187 | * 188 | * - Multiplication cannot overflow. 189 | */ 190 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 191 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 192 | // benefit is lost if 'b' is also tested. 193 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 194 | if (a == 0) { 195 | return 0; 196 | } 197 | 198 | uint256 c = a * b; 199 | require(c / a == b, "SafeMath: multiplication overflow"); 200 | 201 | return c; 202 | } 203 | 204 | /** 205 | * @dev Returns the integer division of two unsigned integers. Reverts on 206 | * division by zero. The result is rounded towards zero. 207 | * 208 | * Counterpart to Solidity's `/` operator. Note: this function uses a 209 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 210 | * uses an invalid opcode to revert (consuming all remaining gas). 211 | * 212 | * Requirements: 213 | * 214 | * - The divisor cannot be zero. 215 | */ 216 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 217 | return div(a, b, "SafeMath: division by zero"); 218 | } 219 | 220 | /** 221 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 222 | * division by zero. The result is rounded towards zero. 223 | * 224 | * Counterpart to Solidity's `/` operator. Note: this function uses a 225 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 226 | * uses an invalid opcode to revert (consuming all remaining gas). 227 | * 228 | * Requirements: 229 | * 230 | * - The divisor cannot be zero. 231 | */ 232 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 233 | require(b > 0, errorMessage); 234 | uint256 c = a / b; 235 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 236 | 237 | return c; 238 | } 239 | 240 | /** 241 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 242 | * Reverts when dividing by zero. 243 | * 244 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 245 | * opcode (which leaves remaining gas untouched) while Solidity uses an 246 | * invalid opcode to revert (consuming all remaining gas). 247 | * 248 | * Requirements: 249 | * 250 | * - The divisor cannot be zero. 251 | */ 252 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 253 | return mod(a, b, "SafeMath: modulo by zero"); 254 | } 255 | 256 | /** 257 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 258 | * Reverts with custom message when dividing by zero. 259 | * 260 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 261 | * opcode (which leaves remaining gas untouched) while Solidity uses an 262 | * invalid opcode to revert (consuming all remaining gas). 263 | * 264 | * Requirements: 265 | * 266 | * - The divisor cannot be zero. 267 | */ 268 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 269 | require(b != 0, errorMessage); 270 | return a % b; 271 | } 272 | } 273 | 274 | // File: @openzeppelin/contracts/utils/Address.sol 275 | 276 | 277 | 278 | pragma solidity ^0.6.2; 279 | 280 | /** 281 | * @dev Collection of functions related to the address type 282 | */ 283 | library Address { 284 | /** 285 | * @dev Returns true if `account` is a contract. 286 | * 287 | * [IMPORTANT] 288 | * ==== 289 | * It is unsafe to assume that an address for which this function returns 290 | * false is an externally-owned account (EOA) and not a contract. 291 | * 292 | * Among others, `isContract` will return false for the following 293 | * types of addresses: 294 | * 295 | * - an externally-owned account 296 | * - a contract in construction 297 | * - an address where a contract will be created 298 | * - an address where a contract lived, but was destroyed 299 | * ==== 300 | */ 301 | function isContract(address account) internal view returns (bool) { 302 | // This method relies in extcodesize, which returns 0 for contracts in 303 | // construction, since the code is only stored at the end of the 304 | // constructor execution. 305 | 306 | uint256 size; 307 | // solhint-disable-next-line no-inline-assembly 308 | assembly { size := extcodesize(account) } 309 | return size > 0; 310 | } 311 | 312 | /** 313 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 314 | * `recipient`, forwarding all available gas and reverting on errors. 315 | * 316 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 317 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 318 | * imposed by `transfer`, making them unable to receive funds via 319 | * `transfer`. {sendValue} removes this limitation. 320 | * 321 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 322 | * 323 | * IMPORTANT: because control is transferred to `recipient`, care must be 324 | * taken to not create reentrancy vulnerabilities. Consider using 325 | * {ReentrancyGuard} or the 326 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 327 | */ 328 | function sendValue(address payable recipient, uint256 amount) internal { 329 | require(address(this).balance >= amount, "Address: insufficient balance"); 330 | 331 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 332 | (bool success, ) = recipient.call{ value: amount }(""); 333 | require(success, "Address: unable to send value, recipient may have reverted"); 334 | } 335 | 336 | /** 337 | * @dev Performs a Solidity function call using a low level `call`. A 338 | * plain`call` is an unsafe replacement for a function call: use this 339 | * function instead. 340 | * 341 | * If `target` reverts with a revert reason, it is bubbled up by this 342 | * function (like regular Solidity function calls). 343 | * 344 | * Returns the raw returned data. To convert to the expected return value, 345 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 346 | * 347 | * Requirements: 348 | * 349 | * - `target` must be a contract. 350 | * - calling `target` with `data` must not revert. 351 | * 352 | * _Available since v3.1._ 353 | */ 354 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 355 | return functionCall(target, data, "Address: low-level call failed"); 356 | } 357 | 358 | /** 359 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 360 | * `errorMessage` as a fallback revert reason when `target` reverts. 361 | * 362 | * _Available since v3.1._ 363 | */ 364 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 365 | return _functionCallWithValue(target, data, 0, errorMessage); 366 | } 367 | 368 | /** 369 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 370 | * but also transferring `value` wei to `target`. 371 | * 372 | * Requirements: 373 | * 374 | * - the calling contract must have an ETH balance of at least `value`. 375 | * - the called Solidity function must be `payable`. 376 | * 377 | * _Available since v3.1._ 378 | */ 379 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 380 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 381 | } 382 | 383 | /** 384 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 385 | * with `errorMessage` as a fallback revert reason when `target` reverts. 386 | * 387 | * _Available since v3.1._ 388 | */ 389 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 390 | require(address(this).balance >= value, "Address: insufficient balance for call"); 391 | return _functionCallWithValue(target, data, value, errorMessage); 392 | } 393 | 394 | function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { 395 | require(isContract(target), "Address: call to non-contract"); 396 | 397 | // solhint-disable-next-line avoid-low-level-calls 398 | (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); 399 | if (success) { 400 | return returndata; 401 | } else { 402 | // Look for revert reason and bubble it up if present 403 | if (returndata.length > 0) { 404 | // The easiest way to bubble the revert reason is using memory via assembly 405 | 406 | // solhint-disable-next-line no-inline-assembly 407 | assembly { 408 | let returndata_size := mload(returndata) 409 | revert(add(32, returndata), returndata_size) 410 | } 411 | } else { 412 | revert(errorMessage); 413 | } 414 | } 415 | } 416 | } 417 | 418 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 419 | 420 | 421 | 422 | pragma solidity ^0.6.0; 423 | 424 | 425 | 426 | 427 | 428 | /** 429 | * @dev Implementation of the {IERC20} interface. 430 | * 431 | * This implementation is agnostic to the way tokens are created. This means 432 | * that a supply mechanism has to be added in a derived contract using {_mint}. 433 | * For a generic mechanism see {ERC20PresetMinterPauser}. 434 | * 435 | * TIP: For a detailed writeup see our guide 436 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 437 | * to implement supply mechanisms]. 438 | * 439 | * We have followed general OpenZeppelin guidelines: functions revert instead 440 | * of returning `false` on failure. This behavior is nonetheless conventional 441 | * and does not conflict with the expectations of ERC20 applications. 442 | * 443 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 444 | * This allows applications to reconstruct the allowance for all accounts just 445 | * by listening to said events. Other implementations of the EIP may not emit 446 | * these events, as it isn't required by the specification. 447 | * 448 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 449 | * functions have been added to mitigate the well-known issues around setting 450 | * allowances. See {IERC20-approve}. 451 | */ 452 | contract ERC20 is Context, IERC20 { 453 | using SafeMath for uint256; 454 | using Address for address; 455 | 456 | mapping (address => uint256) private _balances; 457 | 458 | mapping (address => mapping (address => uint256)) private _allowances; 459 | 460 | uint256 private _totalSupply; 461 | 462 | string private _name; 463 | string private _symbol; 464 | uint8 private _decimals; 465 | 466 | /** 467 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 468 | * a default value of 18. 469 | * 470 | * To select a different value for {decimals}, use {_setupDecimals}. 471 | * 472 | * All three of these values are immutable: they can only be set once during 473 | * construction. 474 | */ 475 | constructor (string memory name, string memory symbol) public { 476 | _name = name; 477 | _symbol = symbol; 478 | _decimals = 18; 479 | } 480 | 481 | /** 482 | * @dev Returns the name of the token. 483 | */ 484 | function name() public view returns (string memory) { 485 | return _name; 486 | } 487 | 488 | /** 489 | * @dev Returns the symbol of the token, usually a shorter version of the 490 | * name. 491 | */ 492 | function symbol() public view returns (string memory) { 493 | return _symbol; 494 | } 495 | 496 | /** 497 | * @dev Returns the number of decimals used to get its user representation. 498 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 499 | * be displayed to a user as `5,05` (`505 / 10 ** 2`). 500 | * 501 | * Tokens usually opt for a value of 18, imitating the relationship between 502 | * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is 503 | * called. 504 | * 505 | * NOTE: This information is only used for _display_ purposes: it in 506 | * no way affects any of the arithmetic of the contract, including 507 | * {IERC20-balanceOf} and {IERC20-transfer}. 508 | */ 509 | function decimals() public view returns (uint8) { 510 | return _decimals; 511 | } 512 | 513 | /** 514 | * @dev See {IERC20-totalSupply}. 515 | */ 516 | function totalSupply() public view override returns (uint256) { 517 | return _totalSupply; 518 | } 519 | 520 | /** 521 | * @dev See {IERC20-balanceOf}. 522 | */ 523 | function balanceOf(address account) public view override returns (uint256) { 524 | return _balances[account]; 525 | } 526 | 527 | /** 528 | * @dev See {IERC20-transfer}. 529 | * 530 | * Requirements: 531 | * 532 | * - `recipient` cannot be the zero address. 533 | * - the caller must have a balance of at least `amount`. 534 | */ 535 | function transfer(address recipient, uint256 amount) public virtual override returns (bool) { 536 | _transfer(_msgSender(), recipient, amount); 537 | return true; 538 | } 539 | 540 | /** 541 | * @dev See {IERC20-allowance}. 542 | */ 543 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 544 | return _allowances[owner][spender]; 545 | } 546 | 547 | /** 548 | * @dev See {IERC20-approve}. 549 | * 550 | * Requirements: 551 | * 552 | * - `spender` cannot be the zero address. 553 | */ 554 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 555 | _approve(_msgSender(), spender, amount); 556 | return true; 557 | } 558 | 559 | /** 560 | * @dev See {IERC20-transferFrom}. 561 | * 562 | * Emits an {Approval} event indicating the updated allowance. This is not 563 | * required by the EIP. See the note at the beginning of {ERC20}; 564 | * 565 | * Requirements: 566 | * - `sender` and `recipient` cannot be the zero address. 567 | * - `sender` must have a balance of at least `amount`. 568 | * - the caller must have allowance for ``sender``'s tokens of at least 569 | * `amount`. 570 | */ 571 | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { 572 | _transfer(sender, recipient, amount); 573 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 574 | return true; 575 | } 576 | 577 | /** 578 | * @dev Atomically increases the allowance granted to `spender` by the caller. 579 | * 580 | * This is an alternative to {approve} that can be used as a mitigation for 581 | * problems described in {IERC20-approve}. 582 | * 583 | * Emits an {Approval} event indicating the updated allowance. 584 | * 585 | * Requirements: 586 | * 587 | * - `spender` cannot be the zero address. 588 | */ 589 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 590 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 591 | return true; 592 | } 593 | 594 | /** 595 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 596 | * 597 | * This is an alternative to {approve} that can be used as a mitigation for 598 | * problems described in {IERC20-approve}. 599 | * 600 | * Emits an {Approval} event indicating the updated allowance. 601 | * 602 | * Requirements: 603 | * 604 | * - `spender` cannot be the zero address. 605 | * - `spender` must have allowance for the caller of at least 606 | * `subtractedValue`. 607 | */ 608 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 609 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 610 | return true; 611 | } 612 | 613 | /** 614 | * @dev Moves tokens `amount` from `sender` to `recipient`. 615 | * 616 | * This is internal function is equivalent to {transfer}, and can be used to 617 | * e.g. implement automatic token fees, slashing mechanisms, etc. 618 | * 619 | * Emits a {Transfer} event. 620 | * 621 | * Requirements: 622 | * 623 | * - `sender` cannot be the zero address. 624 | * - `recipient` cannot be the zero address. 625 | * - `sender` must have a balance of at least `amount`. 626 | */ 627 | function _transfer(address sender, address recipient, uint256 amount) internal virtual { 628 | require(sender != address(0), "ERC20: transfer from the zero address"); 629 | require(recipient != address(0), "ERC20: transfer to the zero address"); 630 | 631 | _beforeTokenTransfer(sender, recipient, amount); 632 | 633 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 634 | _balances[recipient] = _balances[recipient].add(amount); 635 | emit Transfer(sender, recipient, amount); 636 | } 637 | 638 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 639 | * the total supply. 640 | * 641 | * Emits a {Transfer} event with `from` set to the zero address. 642 | * 643 | * Requirements 644 | * 645 | * - `to` cannot be the zero address. 646 | */ 647 | function _mint(address account, uint256 amount) internal virtual { 648 | require(account != address(0), "ERC20: mint to the zero address"); 649 | 650 | _beforeTokenTransfer(address(0), account, amount); 651 | 652 | _totalSupply = _totalSupply.add(amount); 653 | _balances[account] = _balances[account].add(amount); 654 | emit Transfer(address(0), account, amount); 655 | } 656 | 657 | /** 658 | * @dev Destroys `amount` tokens from `account`, reducing the 659 | * total supply. 660 | * 661 | * Emits a {Transfer} event with `to` set to the zero address. 662 | * 663 | * Requirements 664 | * 665 | * - `account` cannot be the zero address. 666 | * - `account` must have at least `amount` tokens. 667 | */ 668 | function _burn(address account, uint256 amount) internal virtual { 669 | require(account != address(0), "ERC20: burn from the zero address"); 670 | 671 | _beforeTokenTransfer(account, address(0), amount); 672 | 673 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 674 | _totalSupply = _totalSupply.sub(amount); 675 | emit Transfer(account, address(0), amount); 676 | } 677 | 678 | /** 679 | * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. 680 | * 681 | * This internal function is equivalent to `approve`, and can be used to 682 | * e.g. set automatic allowances for certain subsystems, etc. 683 | * 684 | * Emits an {Approval} event. 685 | * 686 | * Requirements: 687 | * 688 | * - `owner` cannot be the zero address. 689 | * - `spender` cannot be the zero address. 690 | */ 691 | function _approve(address owner, address spender, uint256 amount) internal virtual { 692 | require(owner != address(0), "ERC20: approve from the zero address"); 693 | require(spender != address(0), "ERC20: approve to the zero address"); 694 | 695 | _allowances[owner][spender] = amount; 696 | emit Approval(owner, spender, amount); 697 | } 698 | 699 | /** 700 | * @dev Sets {decimals} to a value other than the default one of 18. 701 | * 702 | * WARNING: This function should only be called from the constructor. Most 703 | * applications that interact with token contracts will not expect 704 | * {decimals} to ever change, and may work incorrectly if it does. 705 | */ 706 | function _setupDecimals(uint8 decimals_) internal { 707 | _decimals = decimals_; 708 | } 709 | 710 | /** 711 | * @dev Hook that is called before any transfer of tokens. This includes 712 | * minting and burning. 713 | * 714 | * Calling conditions: 715 | * 716 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 717 | * will be to transferred to `to`. 718 | * - when `from` is zero, `amount` tokens will be minted for `to`. 719 | * - when `to` is zero, `amount` of ``from``'s tokens will be burned. 720 | * - `from` and `to` are never both zero. 721 | * 722 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 723 | */ 724 | function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } 725 | } 726 | 727 | // File: @openzeppelin/contracts/access/Ownable.sol 728 | 729 | 730 | 731 | pragma solidity ^0.6.0; 732 | 733 | /** 734 | * @dev Contract module which provides a basic access control mechanism, where 735 | * there is an account (an owner) that can be granted exclusive access to 736 | * specific functions. 737 | * 738 | * By default, the owner account will be the one that deploys the contract. This 739 | * can later be changed with {transferOwnership}. 740 | * 741 | * This module is used through inheritance. It will make available the modifier 742 | * `onlyOwner`, which can be applied to your functions to restrict their use to 743 | * the owner. 744 | */ 745 | contract Ownable is Context { 746 | address private _owner; 747 | 748 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 749 | 750 | /** 751 | * @dev Initializes the contract setting the deployer as the initial owner. 752 | */ 753 | constructor () internal { 754 | address msgSender = _msgSender(); 755 | _owner = msgSender; 756 | emit OwnershipTransferred(address(0), msgSender); 757 | } 758 | 759 | /** 760 | * @dev Returns the address of the current owner. 761 | */ 762 | function owner() public view returns (address) { 763 | return _owner; 764 | } 765 | 766 | /** 767 | * @dev Throws if called by any account other than the owner. 768 | */ 769 | modifier onlyOwner() { 770 | require(_owner == _msgSender(), "Ownable: caller is not the owner"); 771 | _; 772 | } 773 | 774 | /** 775 | * @dev Leaves the contract without owner. It will not be possible to call 776 | * `onlyOwner` functions anymore. Can only be called by the current owner. 777 | * 778 | * NOTE: Renouncing ownership will leave the contract without an owner, 779 | * thereby removing any functionality that is only available to the owner. 780 | */ 781 | function renounceOwnership() public virtual onlyOwner { 782 | emit OwnershipTransferred(_owner, address(0)); 783 | _owner = address(0); 784 | } 785 | 786 | /** 787 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 788 | * Can only be called by the current owner. 789 | */ 790 | function transferOwnership(address newOwner) public virtual onlyOwner { 791 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 792 | emit OwnershipTransferred(_owner, newOwner); 793 | _owner = newOwner; 794 | } 795 | } 796 | 797 | // File: contracts/ONEPOOL.sol 798 | 799 | // File: @openzeppelin/contracts/GSN/Context.sol 800 | 801 | 802 | 803 | pragma solidity ^0.6.12; 804 | 805 | 806 | 807 | 808 | 809 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 810 | 811 | 812 | /** 813 | * @dev Implementation of the {IERC20} interface. 814 | * 815 | * This implementation is agnostic to the way tokens are created. This means 816 | * that a supply mechanism has to be added in a derived contract using {_mint}. 817 | * For a generic mechanism see {ERC20PresetMinterPauser}. 818 | * 819 | * TIP: For a detailed writeup see our guide 820 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 821 | * to implement supply mechanisms]. 822 | * 823 | * We have followed general OpenZeppelin guidelines: functions revert instead 824 | * of returning `false` on failure. This behavior is nonetheless conventional 825 | * and does not conflict with the expectations of ERC20 applications. 826 | * 827 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 828 | * This allows applications to reconstruct the allowance for all accounts just 829 | * by listening to said events. Other implementations of the EIP may not emit 830 | * these events, as it isn't required by the specification. 831 | * 832 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 833 | * functions have been added to mitigate the well-known issues around setting 834 | * allowances. See {IERC20-approve}. 835 | */ 836 | contract ERC20Basic is Context, IERC20 , Ownable{ 837 | using SafeMath for uint256; 838 | using Address for address; 839 | 840 | mapping (address => uint256) private _balances; 841 | 842 | mapping (address => mapping (address => uint256)) private _allowances; 843 | 844 | uint256 private _totalSupply; 845 | 846 | string private _name; 847 | string private _symbol; 848 | uint8 private _decimals; 849 | 850 | 851 | // A record of each accounts delegate 852 | mapping (address => address) internal _delegates; 853 | 854 | /// @notice A checkpoint for marking number of votes from a given block 855 | struct Checkpoint { 856 | uint32 fromBlock; 857 | uint256 votes; 858 | } 859 | 860 | /// @notice A record of votes checkpoints for each account, by index 861 | mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; 862 | 863 | /// @notice The number of checkpoints for each account 864 | mapping (address => uint32) public numCheckpoints; 865 | 866 | /// @notice The EIP-712 typehash for the contract's domain 867 | bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); 868 | 869 | /// @notice The EIP-712 typehash for the delegation struct used by the contract 870 | bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); 871 | 872 | /// @notice A record of states for signing / validating signatures 873 | mapping (address => uint) public nonces; 874 | 875 | /// @notice An event thats emitted when an account changes its delegate 876 | event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); 877 | 878 | /// @notice An event thats emitted when a delegate account's vote balance changes 879 | event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance); 880 | 881 | 882 | /** 883 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 884 | * a default value of 18. 885 | * 886 | * To select a different value for {decimals}, use {_setupDecimals}. 887 | * 888 | * All three of these values are immutable: they can only be set once during 889 | * construction. 890 | */ 891 | constructor (string memory name, string memory symbol) public { 892 | _name = name; 893 | _symbol = symbol; 894 | _decimals = 18; 895 | } 896 | 897 | /** 898 | * @dev Returns the name of the token. 899 | */ 900 | function name() public view returns (string memory) { 901 | return _name; 902 | } 903 | 904 | /** 905 | * @dev Returns the symbol of the token, usually a shorter version of the 906 | * name. 907 | */ 908 | function symbol() public view returns (string memory) { 909 | return _symbol; 910 | } 911 | 912 | /** 913 | * @dev Returns the number of decimals used to get its user representation. 914 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 915 | * be displayed to a user as `5,05` (`505 / 10 ** 2`). 916 | * 917 | * Tokens usually opt for a value of 18, imitating the relationship between 918 | * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is 919 | * called. 920 | * 921 | * NOTE: This information is only used for _display_ purposes: it in 922 | * no way affects any of the arithmetic of the contract, including 923 | * {IERC20-balanceOf} and {IERC20-transfer}. 924 | */ 925 | function decimals() public view returns (uint8) { 926 | return _decimals; 927 | } 928 | 929 | /** 930 | * @dev See {IERC20-totalSupply}. 931 | */ 932 | function totalSupply() public view override returns (uint256) { 933 | return _totalSupply; 934 | } 935 | 936 | function balanceOf(address account) public view override returns (uint256) { 937 | return _balances[account]; 938 | } 939 | 940 | 941 | /** 942 | * @dev See {IERC20-transfer}. 943 | * 944 | * Requirements: 945 | * 946 | * - `recipient` cannot be the zero address. 947 | * - the caller must have a balance of at least `amount`. 948 | */ 949 | function transfer(address recipient, uint256 amount) public virtual override returns (bool) { 950 | _transfer(_msgSender(), recipient, amount); 951 | return true; 952 | } 953 | 954 | /** 955 | * @dev See {IERC20-allowance}. 956 | */ 957 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 958 | return _allowances[owner][spender]; 959 | } 960 | 961 | /** 962 | * @dev See {IERC20-approve}. 963 | * 964 | * Requirements: 965 | * 966 | * - `spender` cannot be the zero address. 967 | */ 968 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 969 | _approve(_msgSender(), spender, amount); 970 | return true; 971 | } 972 | 973 | /** 974 | * @dev See {IERC20-transferFrom}. 975 | * 976 | * Emits an {Approval} event indicating the updated allowance. This is not 977 | * required by the EIP. See the note at the beginning of {ERC20}; 978 | * 979 | * Requirements: 980 | * - `sender` and `recipient` cannot be the zero address. 981 | * - `sender` must have a balance of at least `amount`. 982 | * - the caller must have allowance for ``sender``'s tokens of at least 983 | * `amount`. 984 | */ 985 | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { 986 | _transfer(sender, recipient, amount); 987 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 988 | return true; 989 | } 990 | 991 | /** 992 | * @dev Atomically increases the allowance granted to `spender` by the caller. 993 | * 994 | * This is an alternative to {approve} that can be used as a mitigation for 995 | * problems described in {IERC20-approve}. 996 | * 997 | * Emits an {Approval} event indicating the updated allowance. 998 | * 999 | * Requirements: 1000 | * 1001 | * - `spender` cannot be the zero address. 1002 | */ 1003 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 1004 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 1005 | return true; 1006 | } 1007 | 1008 | /** 1009 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 1010 | * 1011 | * This is an alternative to {approve} that can be used as a mitigation for 1012 | * problems described in {IERC20-approve}. 1013 | * 1014 | * Emits an {Approval} event indicating the updated allowance. 1015 | * 1016 | * Requirements: 1017 | * 1018 | * - `spender` cannot be the zero address. 1019 | * - `spender` must have allowance for the caller of at least 1020 | * `subtractedValue`. 1021 | */ 1022 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 1023 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 1024 | return true; 1025 | } 1026 | 1027 | /** 1028 | * @dev Moves tokens `amount` from `sender` to `recipient`. 1029 | * 1030 | * This is internal function is equivalent to {transfer}, and can be used to 1031 | * e.g. implement automatic token fees, slashing mechanisms, etc. 1032 | * 1033 | * Emits a {Transfer} event. 1034 | * 1035 | * Requirements: 1036 | * 1037 | * - `sender` cannot be the zero address. 1038 | * - `recipient` cannot be the zero address. 1039 | * - `sender` must have a balance of at least `amount`. 1040 | */ 1041 | function _transfer(address sender, address recipient, uint256 amount) internal virtual { 1042 | require(sender != address(0), "ERC20: transfer from the zero address"); 1043 | require(recipient != address(0), "ERC20: transfer to the zero address"); 1044 | 1045 | _beforeTokenTransfer(sender, recipient, amount); 1046 | 1047 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 1048 | _balances[recipient] = _balances[recipient].add(amount); 1049 | _moveDelegates(_delegates[sender], _delegates[recipient], amount); 1050 | emit Transfer(sender, recipient, amount); 1051 | } 1052 | 1053 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 1054 | * the total supply. 1055 | * 1056 | * Emits a {Transfer} event with `from` set to the zero address. 1057 | * 1058 | * Requirements 1059 | * 1060 | * - `to` cannot be the zero address. 1061 | */ 1062 | function _mint(address account, uint256 amount) internal virtual { 1063 | require(account != address(0), "ERC20: mint to the zero address"); 1064 | 1065 | _beforeTokenTransfer(address(0), account, amount); 1066 | 1067 | _totalSupply = _totalSupply.add(amount); 1068 | _balances[account] = _balances[account].add(amount); 1069 | _moveDelegates(address(0), _delegates[account], amount); 1070 | emit Transfer(address(0), account, amount); 1071 | } 1072 | 1073 | /** 1074 | * @dev Destroys `amount` tokens from `account`, reducing the 1075 | * total supply. 1076 | * 1077 | * Emits a {Transfer} event with `to` set to the zero address. 1078 | * 1079 | * Requirements 1080 | * 1081 | * - `account` cannot be the zero address. 1082 | * - `account` must have at least `amount` tokens. 1083 | */ 1084 | function _burn(address account, uint256 amount) internal virtual { 1085 | require(account != address(0), "ERC20: burn from the zero address"); 1086 | 1087 | _beforeTokenTransfer(account, address(0), amount); 1088 | 1089 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 1090 | _totalSupply = _totalSupply.sub(amount); 1091 | emit Transfer(account, address(0), amount); 1092 | } 1093 | 1094 | 1095 | 1096 | 1097 | /** 1098 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 1099 | * 1100 | * This is internal function is equivalent to `approve`, and can be used to 1101 | * e.g. set automatic allowances for certain subsystems, etc. 1102 | * 1103 | * Emits an {Approval} event. 1104 | * 1105 | * Requirements: 1106 | * 1107 | * - `owner` cannot be the zero address. 1108 | * - `spender` cannot be the zero address. 1109 | */ 1110 | function _approve(address owner, address spender, uint256 amount) internal virtual { 1111 | require(owner != address(0), "ERC20: approve from the zero address"); 1112 | require(spender != address(0), "ERC20: approve to the zero address"); 1113 | 1114 | _allowances[owner][spender] = amount; 1115 | emit Approval(owner, spender, amount); 1116 | } 1117 | 1118 | /** 1119 | * @dev Sets {decimals} to a value other than the default one of 18. 1120 | * 1121 | * WARNING: This function should only be called from the constructor. Most 1122 | * applications that interact with token contracts will not expect 1123 | * {decimals} to ever change, and may work incorrectly if it does. 1124 | */ 1125 | function _setupDecimals(uint8 decimals_) internal { 1126 | _decimals = decimals_; 1127 | } 1128 | 1129 | 1130 | function _delegate(address delegator, address delegatee) 1131 | internal 1132 | { 1133 | address currentDelegate = _delegates[delegator]; 1134 | uint256 delegatorBalance = balanceOf(delegator); // balance of underlying (not scaled); 1135 | _delegates[delegator] = delegatee; 1136 | 1137 | emit DelegateChanged(delegator, currentDelegate, delegatee); 1138 | 1139 | _moveDelegates(currentDelegate, delegatee, delegatorBalance); 1140 | } 1141 | 1142 | function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal { 1143 | if (srcRep != dstRep && amount > 0) { 1144 | if (srcRep != address(0)) { 1145 | // decrease old representative 1146 | uint32 srcRepNum = numCheckpoints[srcRep]; 1147 | uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; 1148 | uint256 srcRepNew = srcRepOld.sub(amount); 1149 | _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); 1150 | } 1151 | 1152 | if (dstRep != address(0)) { 1153 | // increase new representative 1154 | uint32 dstRepNum = numCheckpoints[dstRep]; 1155 | uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; 1156 | uint256 dstRepNew = dstRepOld.add(amount); 1157 | _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); 1158 | } 1159 | } 1160 | } 1161 | 1162 | function _writeCheckpoint( 1163 | address delegatee, 1164 | uint32 nCheckpoints, 1165 | uint256 oldVotes, 1166 | uint256 newVotes 1167 | ) 1168 | internal 1169 | { 1170 | uint32 blockNumber = safe32(block.number, "_writeCheckpoint: block number exceeds 32 bits"); 1171 | 1172 | if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { 1173 | checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; 1174 | } else { 1175 | checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); 1176 | numCheckpoints[delegatee] = nCheckpoints + 1; 1177 | } 1178 | 1179 | emit DelegateVotesChanged(delegatee, oldVotes, newVotes); 1180 | } 1181 | 1182 | function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { 1183 | require(n < 2**32, errorMessage); 1184 | return uint32(n); 1185 | } 1186 | 1187 | function getChainId() internal pure returns (uint) { 1188 | uint256 chainId; 1189 | assembly { chainId := chainid() } 1190 | return chainId; 1191 | } 1192 | /** 1193 | * @dev Hook that is called before any transfer of tokens. This includes 1194 | * minting and burning. 1195 | * 1196 | * Calling conditions: 1197 | * 1198 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 1199 | * will be to transferred to `to`. 1200 | * - when `from` is zero, `amount` tokens will be minted for `to`. 1201 | * - when `to` is zero, `amount` of ``from``'s tokens will be burned. 1202 | * - `from` and `to` are never both zero. 1203 | * 1204 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 1205 | */ 1206 | function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } 1207 | } 1208 | 1209 | 1210 | // Token with Governance. 1211 | contract ONEPOOL is ERC20Basic { 1212 | 1213 | //Initialize Token name, symbol, decimal and totalsupply 1214 | constructor () public ERC20Basic ("1pool", "1POOL") { 1215 | 1216 | } 1217 | 1218 | /** 1219 | * @dev Burns a specific amount of tokens. Can be executed by contract Operator only. 1220 | * @param _value The amount of token to be burned. 1221 | */ 1222 | 1223 | function burn(uint256 _value) public onlyOwner { 1224 | _burn(msg.sender,_value); 1225 | } 1226 | 1227 | function mint(address _account, uint256 _value) public onlyOwner returns(bool) { 1228 | _mint(_account, _value); 1229 | return true; 1230 | } 1231 | 1232 | /** 1233 | * @notice Delegate votes from `msg.sender` to `delegatee` 1234 | * @param delegator The address to get delegatee for 1235 | */ 1236 | function delegates(address delegator) 1237 | external 1238 | view 1239 | returns (address) 1240 | { 1241 | return _delegates[delegator]; 1242 | } 1243 | 1244 | /** 1245 | * @notice Delegate votes from `msg.sender` to `delegatee` 1246 | * @param delegatee The address to delegate votes to 1247 | */ 1248 | function delegate(address delegatee) external { 1249 | return _delegate(msg.sender, delegatee); 1250 | } 1251 | 1252 | /** 1253 | * @notice Delegates votes from signatory to `delegatee` 1254 | * @param delegatee The address to delegate votes to 1255 | * @param nonce The contract state required to match the signature 1256 | * @param expiry The time at which to expire the signature 1257 | * @param v The recovery byte of the signature 1258 | * @param r Half of the ECDSA signature pair 1259 | * @param s Half of the ECDSA signature pair 1260 | */ 1261 | function delegateBySig( 1262 | address delegatee, 1263 | uint nonce, 1264 | uint expiry, 1265 | uint8 v, 1266 | bytes32 r, 1267 | bytes32 s 1268 | ) 1269 | external 1270 | 1271 | { 1272 | bytes32 domainSeparator = keccak256( 1273 | abi.encode( 1274 | DOMAIN_TYPEHASH, 1275 | keccak256(bytes(name())), 1276 | getChainId(), 1277 | address(this) 1278 | ) 1279 | ); 1280 | 1281 | bytes32 structHash = keccak256( 1282 | abi.encode( 1283 | DELEGATION_TYPEHASH, 1284 | delegatee, 1285 | nonce, 1286 | expiry 1287 | ) 1288 | ); 1289 | 1290 | bytes32 digest = keccak256( 1291 | abi.encodePacked( 1292 | "\x19\x01", 1293 | domainSeparator, 1294 | structHash 1295 | ) 1296 | ); 1297 | 1298 | address signatory = ecrecover(digest, v, r, s); 1299 | require(signatory != address(0), "delegateBySig: invalid signature"); 1300 | require(nonce == nonces[signatory]++, "delegateBySig: invalid nonce"); 1301 | require(now <= expiry, "delegateBySig: signature expired"); 1302 | return _delegate(signatory, delegatee); 1303 | } 1304 | 1305 | /** 1306 | * @notice Gets the current votes balance for `account` 1307 | * @param account The address to get votes balance 1308 | * @return The number of current votes for `account` 1309 | */ 1310 | function getCurrentVotes(address account) 1311 | external 1312 | view 1313 | returns (uint256) 1314 | { 1315 | uint32 nCheckpoints = numCheckpoints[account]; 1316 | return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; 1317 | } 1318 | 1319 | /** 1320 | * @notice Determine the prior number of votes for an account as of a block number 1321 | * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. 1322 | * @param account The address of the account to check 1323 | * @param blockNumber The block number to get the vote balance at 1324 | * @return The number of votes the account had as of the given block 1325 | */ 1326 | function getPriorVotes(address account, uint blockNumber) 1327 | external 1328 | view 1329 | returns (uint256) 1330 | { 1331 | require(blockNumber < block.number, "getPriorVotes: not yet determined"); 1332 | 1333 | uint32 nCheckpoints = numCheckpoints[account]; 1334 | if (nCheckpoints == 0) { 1335 | return 0; 1336 | } 1337 | 1338 | // First check most recent balance 1339 | if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { 1340 | return checkpoints[account][nCheckpoints - 1].votes; 1341 | } 1342 | 1343 | // Next check implicit zero balance 1344 | if (checkpoints[account][0].fromBlock > blockNumber) { 1345 | return 0; 1346 | } 1347 | 1348 | uint32 lower = 0; 1349 | uint32 upper = nCheckpoints - 1; 1350 | while (upper > lower) { 1351 | uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow 1352 | Checkpoint memory cp = checkpoints[account][center]; 1353 | if (cp.fromBlock == blockNumber) { 1354 | return cp.votes; 1355 | } else if (cp.fromBlock < blockNumber) { 1356 | lower = center; 1357 | } else { 1358 | upper = center - 1; 1359 | } 1360 | } 1361 | return checkpoints[account][lower].votes; 1362 | } 1363 | 1364 | 1365 | } 1366 | -------------------------------------------------------------------------------- /RewardPool.sol: -------------------------------------------------------------------------------- 1 | /** 2 | *Submitted for verification at BscScan.com on 2021-07-01 3 | */ 4 | 5 | /** 6 | *Submitted for verification at BscScan.com on 2021-06-05 7 | */ 8 | 9 | // File: @openzeppelin/contracts/token/ERC20/IERC20.sol 10 | 11 | // SPDX-License-Identifier: MIT 12 | 13 | pragma solidity ^0.6.0; 14 | 15 | /** 16 | * @dev Interface of the ERC20 standard as defined in the EIP. 17 | */ 18 | interface IERC20 { 19 | /** 20 | * @dev Returns the amount of tokens in existence. 21 | */ 22 | function totalSupply() external view returns (uint256); 23 | 24 | /** 25 | * @dev Returns the amount of tokens owned by `account`. 26 | */ 27 | function balanceOf(address account) external view returns (uint256); 28 | 29 | /** 30 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 31 | * 32 | * Returns a boolean value indicating whether the operation succeeded. 33 | * 34 | * Emits a {Transfer} event. 35 | */ 36 | function transfer(address recipient, uint256 amount) external returns (bool); 37 | 38 | /** 39 | * @dev Returns the remaining number of tokens that `spender` will be 40 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 41 | * zero by default. 42 | * 43 | * This value changes when {approve} or {transferFrom} are called. 44 | */ 45 | function allowance(address owner, address spender) external view returns (uint256); 46 | 47 | /** 48 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 49 | * 50 | * Returns a boolean value indicating whether the operation succeeded. 51 | * 52 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 53 | * that someone may use both the old and the new allowance by unfortunate 54 | * transaction ordering. One possible solution to mitigate this race 55 | * condition is to first reduce the spender's allowance to 0 and set the 56 | * desired value afterwards: 57 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 58 | * 59 | * Emits an {Approval} event. 60 | */ 61 | function approve(address spender, uint256 amount) external returns (bool); 62 | 63 | /** 64 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 65 | * allowance mechanism. `amount` is then deducted from the caller's 66 | * allowance. 67 | * 68 | * Returns a boolean value indicating whether the operation succeeded. 69 | * 70 | * Emits a {Transfer} event. 71 | */ 72 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 73 | 74 | /** 75 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 76 | * another (`to`). 77 | * 78 | * Note that `value` may be zero. 79 | */ 80 | event Transfer(address indexed from, address indexed to, uint256 value); 81 | 82 | /** 83 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 84 | * a call to {approve}. `value` is the new allowance. 85 | */ 86 | event Approval(address indexed owner, address indexed spender, uint256 value); 87 | } 88 | 89 | // File: @openzeppelin/contracts/math/SafeMath.sol 90 | 91 | 92 | 93 | pragma solidity ^0.6.0; 94 | 95 | /** 96 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 97 | * checks. 98 | * 99 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 100 | * in bugs, because programmers usually assume that an overflow raises an 101 | * error, which is the standard behavior in high level programming languages. 102 | * `SafeMath` restores this intuition by reverting the transaction when an 103 | * operation overflows. 104 | * 105 | * Using this library instead of the unchecked operations eliminates an entire 106 | * class of bugs, so it's recommended to use it always. 107 | */ 108 | library SafeMath { 109 | /** 110 | * @dev Returns the addition of two unsigned integers, reverting on 111 | * overflow. 112 | * 113 | * Counterpart to Solidity's `+` operator. 114 | * 115 | * Requirements: 116 | * 117 | * - Addition cannot overflow. 118 | */ 119 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 120 | uint256 c = a + b; 121 | require(c >= a, "SafeMath: addition overflow"); 122 | 123 | return c; 124 | } 125 | 126 | /** 127 | * @dev Returns the subtraction of two unsigned integers, reverting on 128 | * overflow (when the result is negative). 129 | * 130 | * Counterpart to Solidity's `-` operator. 131 | * 132 | * Requirements: 133 | * 134 | * - Subtraction cannot overflow. 135 | */ 136 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 137 | return sub(a, b, "SafeMath: subtraction overflow"); 138 | } 139 | 140 | /** 141 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 142 | * overflow (when the result is negative). 143 | * 144 | * Counterpart to Solidity's `-` operator. 145 | * 146 | * Requirements: 147 | * 148 | * - Subtraction cannot overflow. 149 | */ 150 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 151 | require(b <= a, errorMessage); 152 | uint256 c = a - b; 153 | 154 | return c; 155 | } 156 | 157 | /** 158 | * @dev Returns the multiplication of two unsigned integers, reverting on 159 | * overflow. 160 | * 161 | * Counterpart to Solidity's `*` operator. 162 | * 163 | * Requirements: 164 | * 165 | * - Multiplication cannot overflow. 166 | */ 167 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 168 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 169 | // benefit is lost if 'b' is also tested. 170 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 171 | if (a == 0) { 172 | return 0; 173 | } 174 | 175 | uint256 c = a * b; 176 | require(c / a == b, "SafeMath: multiplication overflow"); 177 | 178 | return c; 179 | } 180 | 181 | /** 182 | * @dev Returns the integer division of two unsigned integers. Reverts on 183 | * division by zero. The result is rounded towards zero. 184 | * 185 | * Counterpart to Solidity's `/` operator. Note: this function uses a 186 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 187 | * uses an invalid opcode to revert (consuming all remaining gas). 188 | * 189 | * Requirements: 190 | * 191 | * - The divisor cannot be zero. 192 | */ 193 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 194 | return div(a, b, "SafeMath: division by zero"); 195 | } 196 | 197 | /** 198 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 199 | * division by zero. The result is rounded towards zero. 200 | * 201 | * Counterpart to Solidity's `/` operator. Note: this function uses a 202 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 203 | * uses an invalid opcode to revert (consuming all remaining gas). 204 | * 205 | * Requirements: 206 | * 207 | * - The divisor cannot be zero. 208 | */ 209 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 210 | require(b > 0, errorMessage); 211 | uint256 c = a / b; 212 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 213 | 214 | return c; 215 | } 216 | 217 | /** 218 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 219 | * Reverts when dividing by zero. 220 | * 221 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 222 | * opcode (which leaves remaining gas untouched) while Solidity uses an 223 | * invalid opcode to revert (consuming all remaining gas). 224 | * 225 | * Requirements: 226 | * 227 | * - The divisor cannot be zero. 228 | */ 229 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 230 | return mod(a, b, "SafeMath: modulo by zero"); 231 | } 232 | 233 | /** 234 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 235 | * Reverts with custom message when dividing by zero. 236 | * 237 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 238 | * opcode (which leaves remaining gas untouched) while Solidity uses an 239 | * invalid opcode to revert (consuming all remaining gas). 240 | * 241 | * Requirements: 242 | * 243 | * - The divisor cannot be zero. 244 | */ 245 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 246 | require(b != 0, errorMessage); 247 | return a % b; 248 | } 249 | } 250 | 251 | // File: @openzeppelin/contracts/utils/Address.sol 252 | 253 | 254 | 255 | pragma solidity ^0.6.2; 256 | 257 | /** 258 | * @dev Collection of functions related to the address type 259 | */ 260 | library Address { 261 | /** 262 | * @dev Returns true if `account` is a contract. 263 | * 264 | * [IMPORTANT] 265 | * ==== 266 | * It is unsafe to assume that an address for which this function returns 267 | * false is an externally-owned account (EOA) and not a contract. 268 | * 269 | * Among others, `isContract` will return false for the following 270 | * types of addresses: 271 | * 272 | * - an externally-owned account 273 | * - a contract in construction 274 | * - an address where a contract will be created 275 | * - an address where a contract lived, but was destroyed 276 | * ==== 277 | */ 278 | function isContract(address account) internal view returns (bool) { 279 | // This method relies in extcodesize, which returns 0 for contracts in 280 | // construction, since the code is only stored at the end of the 281 | // constructor execution. 282 | 283 | uint256 size; 284 | // solhint-disable-next-line no-inline-assembly 285 | assembly { size := extcodesize(account) } 286 | return size > 0; 287 | } 288 | 289 | /** 290 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 291 | * `recipient`, forwarding all available gas and reverting on errors. 292 | * 293 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 294 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 295 | * imposed by `transfer`, making them unable to receive funds via 296 | * `transfer`. {sendValue} removes this limitation. 297 | * 298 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 299 | * 300 | * IMPORTANT: because control is transferred to `recipient`, care must be 301 | * taken to not create reentrancy vulnerabilities. Consider using 302 | * {ReentrancyGuard} or the 303 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 304 | */ 305 | function sendValue(address payable recipient, uint256 amount) internal { 306 | require(address(this).balance >= amount, "Address: insufficient balance"); 307 | 308 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 309 | (bool success, ) = recipient.call{ value: amount }(""); 310 | require(success, "Address: unable to send value, recipient may have reverted"); 311 | } 312 | 313 | /** 314 | * @dev Performs a Solidity function call using a low level `call`. A 315 | * plain`call` is an unsafe replacement for a function call: use this 316 | * function instead. 317 | * 318 | * If `target` reverts with a revert reason, it is bubbled up by this 319 | * function (like regular Solidity function calls). 320 | * 321 | * Returns the raw returned data. To convert to the expected return value, 322 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 323 | * 324 | * Requirements: 325 | * 326 | * - `target` must be a contract. 327 | * - calling `target` with `data` must not revert. 328 | * 329 | * _Available since v3.1._ 330 | */ 331 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 332 | return functionCall(target, data, "Address: low-level call failed"); 333 | } 334 | 335 | /** 336 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 337 | * `errorMessage` as a fallback revert reason when `target` reverts. 338 | * 339 | * _Available since v3.1._ 340 | */ 341 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 342 | return _functionCallWithValue(target, data, 0, errorMessage); 343 | } 344 | 345 | /** 346 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 347 | * but also transferring `value` wei to `target`. 348 | * 349 | * Requirements: 350 | * 351 | * - the calling contract must have an ETH balance of at least `value`. 352 | * - the called Solidity function must be `payable`. 353 | * 354 | * _Available since v3.1._ 355 | */ 356 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 357 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 358 | } 359 | 360 | /** 361 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 362 | * with `errorMessage` as a fallback revert reason when `target` reverts. 363 | * 364 | * _Available since v3.1._ 365 | */ 366 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 367 | require(address(this).balance >= value, "Address: insufficient balance for call"); 368 | return _functionCallWithValue(target, data, value, errorMessage); 369 | } 370 | 371 | function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { 372 | require(isContract(target), "Address: call to non-contract"); 373 | 374 | // solhint-disable-next-line avoid-low-level-calls 375 | (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); 376 | if (success) { 377 | return returndata; 378 | } else { 379 | // Look for revert reason and bubble it up if present 380 | if (returndata.length > 0) { 381 | // The easiest way to bubble the revert reason is using memory via assembly 382 | 383 | // solhint-disable-next-line no-inline-assembly 384 | assembly { 385 | let returndata_size := mload(returndata) 386 | revert(add(32, returndata), returndata_size) 387 | } 388 | } else { 389 | revert(errorMessage); 390 | } 391 | } 392 | } 393 | } 394 | 395 | // File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol 396 | 397 | 398 | 399 | pragma solidity ^0.6.0; 400 | 401 | 402 | 403 | 404 | /** 405 | * @title SafeERC20 406 | * @dev Wrappers around ERC20 operations that throw on failure (when the token 407 | * contract returns false). Tokens that return no value (and instead revert or 408 | * throw on failure) are also supported, non-reverting calls are assumed to be 409 | * successful. 410 | * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, 411 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 412 | */ 413 | library SafeERC20 { 414 | using SafeMath for uint256; 415 | using Address for address; 416 | 417 | function safeTransfer(IERC20 token, address to, uint256 value) internal { 418 | _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 419 | } 420 | 421 | function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { 422 | _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 423 | } 424 | 425 | /** 426 | * @dev Deprecated. This function has issues similar to the ones found in 427 | * {IERC20-approve}, and its usage is discouraged. 428 | * 429 | * Whenever possible, use {safeIncreaseAllowance} and 430 | * {safeDecreaseAllowance} instead. 431 | */ 432 | function safeApprove(IERC20 token, address spender, uint256 value) internal { 433 | // safeApprove should only be called when setting an initial allowance, 434 | // or when resetting it to zero. To increase and decrease it, use 435 | // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' 436 | // solhint-disable-next-line max-line-length 437 | require((value == 0) || (token.allowance(address(this), spender) == 0), 438 | "SafeERC20: approve from non-zero to non-zero allowance" 439 | ); 440 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 441 | } 442 | 443 | function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { 444 | uint256 newAllowance = token.allowance(address(this), spender).add(value); 445 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 446 | } 447 | 448 | function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { 449 | uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); 450 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 451 | } 452 | 453 | /** 454 | * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement 455 | * on the return value: the return value is optional (but if data is returned, it must not be false). 456 | * @param token The token targeted by the call. 457 | * @param data The call data (encoded using abi.encode or one of its variants). 458 | */ 459 | function _callOptionalReturn(IERC20 token, bytes memory data) private { 460 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since 461 | // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that 462 | // the target address contains contract code and also asserts for success in the low-level call. 463 | 464 | bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); 465 | if (returndata.length > 0) { // Return data is optional 466 | // solhint-disable-next-line max-line-length 467 | require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); 468 | } 469 | } 470 | } 471 | 472 | // File: @openzeppelin/contracts/utils/EnumerableSet.sol 473 | 474 | 475 | 476 | pragma solidity ^0.6.0; 477 | 478 | /** 479 | * @dev Library for managing 480 | * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive 481 | * types. 482 | * 483 | * Sets have the following properties: 484 | * 485 | * - Elements are added, removed, and checked for existence in constant time 486 | * (O(1)). 487 | * - Elements are enumerated in O(n). No guarantees are made on the ordering. 488 | * 489 | * ``` 490 | * contract Example { 491 | * // Add the library methods 492 | * using EnumerableSet for EnumerableSet.AddressSet; 493 | * 494 | * // Declare a set state variable 495 | * EnumerableSet.AddressSet private mySet; 496 | * } 497 | * ``` 498 | * 499 | * As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256` 500 | * (`UintSet`) are supported. 501 | */ 502 | library EnumerableSet { 503 | // To implement this library for multiple types with as little code 504 | // repetition as possible, we write it in terms of a generic Set type with 505 | // bytes32 values. 506 | // The Set implementation uses private functions, and user-facing 507 | // implementations (such as AddressSet) are just wrappers around the 508 | // underlying Set. 509 | // This means that we can only create new EnumerableSets for types that fit 510 | // in bytes32. 511 | 512 | struct Set { 513 | // Storage of set values 514 | bytes32[] _values; 515 | 516 | // Position of the value in the `values` array, plus 1 because index 0 517 | // means a value is not in the set. 518 | mapping (bytes32 => uint256) _indexes; 519 | } 520 | 521 | /** 522 | * @dev Add a value to a set. O(1). 523 | * 524 | * Returns true if the value was added to the set, that is if it was not 525 | * already present. 526 | */ 527 | function _add(Set storage set, bytes32 value) private returns (bool) { 528 | if (!_contains(set, value)) { 529 | set._values.push(value); 530 | // The value is stored at length-1, but we add 1 to all indexes 531 | // and use 0 as a sentinel value 532 | set._indexes[value] = set._values.length; 533 | return true; 534 | } else { 535 | return false; 536 | } 537 | } 538 | 539 | /** 540 | * @dev Removes a value from a set. O(1). 541 | * 542 | * Returns true if the value was removed from the set, that is if it was 543 | * present. 544 | */ 545 | function _remove(Set storage set, bytes32 value) private returns (bool) { 546 | // We read and store the value's index to prevent multiple reads from the same storage slot 547 | uint256 valueIndex = set._indexes[value]; 548 | 549 | if (valueIndex != 0) { // Equivalent to contains(set, value) 550 | // To delete an element from the _values array in O(1), we swap the element to delete with the last one in 551 | // the array, and then remove the last element (sometimes called as 'swap and pop'). 552 | // This modifies the order of the array, as noted in {at}. 553 | 554 | uint256 toDeleteIndex = valueIndex - 1; 555 | uint256 lastIndex = set._values.length - 1; 556 | 557 | // When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs 558 | // so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement. 559 | 560 | bytes32 lastvalue = set._values[lastIndex]; 561 | 562 | // Move the last value to the index where the value to delete is 563 | set._values[toDeleteIndex] = lastvalue; 564 | // Update the index for the moved value 565 | set._indexes[lastvalue] = toDeleteIndex + 1; // All indexes are 1-based 566 | 567 | // Delete the slot where the moved value was stored 568 | set._values.pop(); 569 | 570 | // Delete the index for the deleted slot 571 | delete set._indexes[value]; 572 | 573 | return true; 574 | } else { 575 | return false; 576 | } 577 | } 578 | 579 | /** 580 | * @dev Returns true if the value is in the set. O(1). 581 | */ 582 | function _contains(Set storage set, bytes32 value) private view returns (bool) { 583 | return set._indexes[value] != 0; 584 | } 585 | 586 | /** 587 | * @dev Returns the number of values on the set. O(1). 588 | */ 589 | function _length(Set storage set) private view returns (uint256) { 590 | return set._values.length; 591 | } 592 | 593 | /** 594 | * @dev Returns the value stored at position `index` in the set. O(1). 595 | * 596 | * Note that there are no guarantees on the ordering of values inside the 597 | * array, and it may change when more values are added or removed. 598 | * 599 | * Requirements: 600 | * 601 | * - `index` must be strictly less than {length}. 602 | */ 603 | function _at(Set storage set, uint256 index) private view returns (bytes32) { 604 | require(set._values.length > index, "EnumerableSet: index out of bounds"); 605 | return set._values[index]; 606 | } 607 | 608 | // AddressSet 609 | 610 | struct AddressSet { 611 | Set _inner; 612 | } 613 | 614 | /** 615 | * @dev Add a value to a set. O(1). 616 | * 617 | * Returns true if the value was added to the set, that is if it was not 618 | * already present. 619 | */ 620 | function add(AddressSet storage set, address value) internal returns (bool) { 621 | return _add(set._inner, bytes32(uint256(value))); 622 | } 623 | 624 | /** 625 | * @dev Removes a value from a set. O(1). 626 | * 627 | * Returns true if the value was removed from the set, that is if it was 628 | * present. 629 | */ 630 | function remove(AddressSet storage set, address value) internal returns (bool) { 631 | return _remove(set._inner, bytes32(uint256(value))); 632 | } 633 | 634 | /** 635 | * @dev Returns true if the value is in the set. O(1). 636 | */ 637 | function contains(AddressSet storage set, address value) internal view returns (bool) { 638 | return _contains(set._inner, bytes32(uint256(value))); 639 | } 640 | 641 | /** 642 | * @dev Returns the number of values in the set. O(1). 643 | */ 644 | function length(AddressSet storage set) internal view returns (uint256) { 645 | return _length(set._inner); 646 | } 647 | 648 | /** 649 | * @dev Returns the value stored at position `index` in the set. O(1). 650 | * 651 | * Note that there are no guarantees on the ordering of values inside the 652 | * array, and it may change when more values are added or removed. 653 | * 654 | * Requirements: 655 | * 656 | * - `index` must be strictly less than {length}. 657 | */ 658 | function at(AddressSet storage set, uint256 index) internal view returns (address) { 659 | return address(uint256(_at(set._inner, index))); 660 | } 661 | 662 | 663 | // UintSet 664 | 665 | struct UintSet { 666 | Set _inner; 667 | } 668 | 669 | /** 670 | * @dev Add a value to a set. O(1). 671 | * 672 | * Returns true if the value was added to the set, that is if it was not 673 | * already present. 674 | */ 675 | function add(UintSet storage set, uint256 value) internal returns (bool) { 676 | return _add(set._inner, bytes32(value)); 677 | } 678 | 679 | /** 680 | * @dev Removes a value from a set. O(1). 681 | * 682 | * Returns true if the value was removed from the set, that is if it was 683 | * present. 684 | */ 685 | function remove(UintSet storage set, uint256 value) internal returns (bool) { 686 | return _remove(set._inner, bytes32(value)); 687 | } 688 | 689 | /** 690 | * @dev Returns true if the value is in the set. O(1). 691 | */ 692 | function contains(UintSet storage set, uint256 value) internal view returns (bool) { 693 | return _contains(set._inner, bytes32(value)); 694 | } 695 | 696 | /** 697 | * @dev Returns the number of values on the set. O(1). 698 | */ 699 | function length(UintSet storage set) internal view returns (uint256) { 700 | return _length(set._inner); 701 | } 702 | 703 | /** 704 | * @dev Returns the value stored at position `index` in the set. O(1). 705 | * 706 | * Note that there are no guarantees on the ordering of values inside the 707 | * array, and it may change when more values are added or removed. 708 | * 709 | * Requirements: 710 | * 711 | * - `index` must be strictly less than {length}. 712 | */ 713 | function at(UintSet storage set, uint256 index) internal view returns (uint256) { 714 | return uint256(_at(set._inner, index)); 715 | } 716 | } 717 | 718 | // File: @openzeppelin/contracts/GSN/Context.sol 719 | 720 | 721 | 722 | pragma solidity ^0.6.0; 723 | 724 | /* 725 | * @dev Provides information about the current execution context, including the 726 | * sender of the transaction and its data. While these are generally available 727 | * via msg.sender and msg.data, they should not be accessed in such a direct 728 | * manner, since when dealing with GSN meta-transactions the account sending and 729 | * paying for execution may not be the actual sender (as far as an application 730 | * is concerned). 731 | * 732 | * This contract is only required for intermediate, library-like contracts. 733 | */ 734 | abstract contract Context { 735 | function _msgSender() internal view virtual returns (address payable) { 736 | return msg.sender; 737 | } 738 | 739 | function _msgData() internal view virtual returns (bytes memory) { 740 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 741 | return msg.data; 742 | } 743 | } 744 | 745 | // File: @openzeppelin/contracts/access/Ownable.sol 746 | 747 | 748 | 749 | pragma solidity ^0.6.0; 750 | 751 | /** 752 | * @dev Contract module which provides a basic access control mechanism, where 753 | * there is an account (an owner) that can be granted exclusive access to 754 | * specific functions. 755 | * 756 | * By default, the owner account will be the one that deploys the contract. This 757 | * can later be changed with {transferOwnership}. 758 | * 759 | * This module is used through inheritance. It will make available the modifier 760 | * `onlyOwner`, which can be applied to your functions to restrict their use to 761 | * the owner. 762 | */ 763 | contract Ownable is Context { 764 | address private _owner; 765 | 766 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 767 | 768 | /** 769 | * @dev Initializes the contract setting the deployer as the initial owner. 770 | */ 771 | constructor () internal { 772 | address msgSender = _msgSender(); 773 | _owner = msgSender; 774 | emit OwnershipTransferred(address(0), msgSender); 775 | } 776 | 777 | /** 778 | * @dev Returns the address of the current owner. 779 | */ 780 | function owner() public view returns (address) { 781 | return _owner; 782 | } 783 | 784 | /** 785 | * @dev Throws if called by any account other than the owner. 786 | */ 787 | modifier onlyOwner() { 788 | require(_owner == _msgSender(), "Ownable: caller is not the owner"); 789 | _; 790 | } 791 | 792 | /** 793 | * @dev Leaves the contract without owner. It will not be possible to call 794 | * `onlyOwner` functions anymore. Can only be called by the current owner. 795 | * 796 | * NOTE: Renouncing ownership will leave the contract without an owner, 797 | * thereby removing any functionality that is only available to the owner. 798 | */ 799 | function renounceOwnership() public virtual onlyOwner { 800 | emit OwnershipTransferred(_owner, address(0)); 801 | _owner = address(0); 802 | } 803 | 804 | /** 805 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 806 | * Can only be called by the current owner. 807 | */ 808 | function transferOwnership(address newOwner) public virtual onlyOwner { 809 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 810 | emit OwnershipTransferred(_owner, newOwner); 811 | _owner = newOwner; 812 | } 813 | } 814 | 815 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 816 | 817 | 818 | 819 | pragma solidity ^0.6.0; 820 | 821 | 822 | 823 | 824 | 825 | /** 826 | * @dev Implementation of the {IERC20} interface. 827 | * 828 | * This implementation is agnostic to the way tokens are created. This means 829 | * that a supply mechanism has to be added in a derived contract using {_mint}. 830 | * For a generic mechanism see {ERC20PresetMinterPauser}. 831 | * 832 | * TIP: For a detailed writeup see our guide 833 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 834 | * to implement supply mechanisms]. 835 | * 836 | * We have followed general OpenZeppelin guidelines: functions revert instead 837 | * of returning `false` on failure. This behavior is nonetheless conventional 838 | * and does not conflict with the expectations of ERC20 applications. 839 | * 840 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 841 | * This allows applications to reconstruct the allowance for all accounts just 842 | * by listening to said events. Other implementations of the EIP may not emit 843 | * these events, as it isn't required by the specification. 844 | * 845 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 846 | * functions have been added to mitigate the well-known issues around setting 847 | * allowances. See {IERC20-approve}. 848 | */ 849 | contract ERC20 is Context, IERC20 { 850 | using SafeMath for uint256; 851 | using Address for address; 852 | 853 | mapping (address => uint256) private _balances; 854 | 855 | mapping (address => mapping (address => uint256)) private _allowances; 856 | 857 | uint256 private _totalSupply; 858 | 859 | string private _name; 860 | string private _symbol; 861 | uint8 private _decimals; 862 | 863 | /** 864 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 865 | * a default value of 18. 866 | * 867 | * To select a different value for {decimals}, use {_setupDecimals}. 868 | * 869 | * All three of these values are immutable: they can only be set once during 870 | * construction. 871 | */ 872 | constructor (string memory name, string memory symbol) public { 873 | _name = name; 874 | _symbol = symbol; 875 | _decimals = 18; 876 | } 877 | 878 | /** 879 | * @dev Returns the name of the token. 880 | */ 881 | function name() public view returns (string memory) { 882 | return _name; 883 | } 884 | 885 | /** 886 | * @dev Returns the symbol of the token, usually a shorter version of the 887 | * name. 888 | */ 889 | function symbol() public view returns (string memory) { 890 | return _symbol; 891 | } 892 | 893 | /** 894 | * @dev Returns the number of decimals used to get its user representation. 895 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 896 | * be displayed to a user as `5,05` (`505 / 10 ** 2`). 897 | * 898 | * Tokens usually opt for a value of 18, imitating the relationship between 899 | * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is 900 | * called. 901 | * 902 | * NOTE: This information is only used for _display_ purposes: it in 903 | * no way affects any of the arithmetic of the contract, including 904 | * {IERC20-balanceOf} and {IERC20-transfer}. 905 | */ 906 | function decimals() public view returns (uint8) { 907 | return _decimals; 908 | } 909 | 910 | /** 911 | * @dev See {IERC20-totalSupply}. 912 | */ 913 | function totalSupply() public view override returns (uint256) { 914 | return _totalSupply; 915 | } 916 | 917 | /** 918 | * @dev See {IERC20-balanceOf}. 919 | */ 920 | function balanceOf(address account) public view override returns (uint256) { 921 | return _balances[account]; 922 | } 923 | 924 | /** 925 | * @dev See {IERC20-transfer}. 926 | * 927 | * Requirements: 928 | * 929 | * - `recipient` cannot be the zero address. 930 | * - the caller must have a balance of at least `amount`. 931 | */ 932 | function transfer(address recipient, uint256 amount) public virtual override returns (bool) { 933 | _transfer(_msgSender(), recipient, amount); 934 | return true; 935 | } 936 | 937 | /** 938 | * @dev See {IERC20-allowance}. 939 | */ 940 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 941 | return _allowances[owner][spender]; 942 | } 943 | 944 | /** 945 | * @dev See {IERC20-approve}. 946 | * 947 | * Requirements: 948 | * 949 | * - `spender` cannot be the zero address. 950 | */ 951 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 952 | _approve(_msgSender(), spender, amount); 953 | return true; 954 | } 955 | 956 | /** 957 | * @dev See {IERC20-transferFrom}. 958 | * 959 | * Emits an {Approval} event indicating the updated allowance. This is not 960 | * required by the EIP. See the note at the beginning of {ERC20}; 961 | * 962 | * Requirements: 963 | * - `sender` and `recipient` cannot be the zero address. 964 | * - `sender` must have a balance of at least `amount`. 965 | * - the caller must have allowance for ``sender``'s tokens of at least 966 | * `amount`. 967 | */ 968 | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { 969 | _transfer(sender, recipient, amount); 970 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 971 | return true; 972 | } 973 | 974 | /** 975 | * @dev Atomically increases the allowance granted to `spender` by the caller. 976 | * 977 | * This is an alternative to {approve} that can be used as a mitigation for 978 | * problems described in {IERC20-approve}. 979 | * 980 | * Emits an {Approval} event indicating the updated allowance. 981 | * 982 | * Requirements: 983 | * 984 | * - `spender` cannot be the zero address. 985 | */ 986 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 987 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 988 | return true; 989 | } 990 | 991 | /** 992 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 993 | * 994 | * This is an alternative to {approve} that can be used as a mitigation for 995 | * problems described in {IERC20-approve}. 996 | * 997 | * Emits an {Approval} event indicating the updated allowance. 998 | * 999 | * Requirements: 1000 | * 1001 | * - `spender` cannot be the zero address. 1002 | * - `spender` must have allowance for the caller of at least 1003 | * `subtractedValue`. 1004 | */ 1005 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 1006 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 1007 | return true; 1008 | } 1009 | 1010 | /** 1011 | * @dev Moves tokens `amount` from `sender` to `recipient`. 1012 | * 1013 | * This is internal function is equivalent to {transfer}, and can be used to 1014 | * e.g. implement automatic token fees, slashing mechanisms, etc. 1015 | * 1016 | * Emits a {Transfer} event. 1017 | * 1018 | * Requirements: 1019 | * 1020 | * - `sender` cannot be the zero address. 1021 | * - `recipient` cannot be the zero address. 1022 | * - `sender` must have a balance of at least `amount`. 1023 | */ 1024 | function _transfer(address sender, address recipient, uint256 amount) internal virtual { 1025 | require(sender != address(0), "ERC20: transfer from the zero address"); 1026 | require(recipient != address(0), "ERC20: transfer to the zero address"); 1027 | 1028 | _beforeTokenTransfer(sender, recipient, amount); 1029 | 1030 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 1031 | _balances[recipient] = _balances[recipient].add(amount); 1032 | emit Transfer(sender, recipient, amount); 1033 | } 1034 | 1035 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 1036 | * the total supply. 1037 | * 1038 | * Emits a {Transfer} event with `from` set to the zero address. 1039 | * 1040 | * Requirements 1041 | * 1042 | * - `to` cannot be the zero address. 1043 | */ 1044 | function _mint(address account, uint256 amount) internal virtual { 1045 | require(account != address(0), "ERC20: mint to the zero address"); 1046 | 1047 | _beforeTokenTransfer(address(0), account, amount); 1048 | 1049 | _totalSupply = _totalSupply.add(amount); 1050 | _balances[account] = _balances[account].add(amount); 1051 | emit Transfer(address(0), account, amount); 1052 | } 1053 | 1054 | /** 1055 | * @dev Destroys `amount` tokens from `account`, reducing the 1056 | * total supply. 1057 | * 1058 | * Emits a {Transfer} event with `to` set to the zero address. 1059 | * 1060 | * Requirements 1061 | * 1062 | * - `account` cannot be the zero address. 1063 | * - `account` must have at least `amount` tokens. 1064 | */ 1065 | function _burn(address account, uint256 amount) internal virtual { 1066 | require(account != address(0), "ERC20: burn from the zero address"); 1067 | 1068 | _beforeTokenTransfer(account, address(0), amount); 1069 | 1070 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 1071 | _totalSupply = _totalSupply.sub(amount); 1072 | emit Transfer(account, address(0), amount); 1073 | } 1074 | 1075 | /** 1076 | * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. 1077 | * 1078 | * This internal function is equivalent to `approve`, and can be used to 1079 | * e.g. set automatic allowances for certain subsystems, etc. 1080 | * 1081 | * Emits an {Approval} event. 1082 | * 1083 | * Requirements: 1084 | * 1085 | * - `owner` cannot be the zero address. 1086 | * - `spender` cannot be the zero address. 1087 | */ 1088 | function _approve(address owner, address spender, uint256 amount) internal virtual { 1089 | require(owner != address(0), "ERC20: approve from the zero address"); 1090 | require(spender != address(0), "ERC20: approve to the zero address"); 1091 | 1092 | _allowances[owner][spender] = amount; 1093 | emit Approval(owner, spender, amount); 1094 | } 1095 | 1096 | /** 1097 | * @dev Sets {decimals} to a value other than the default one of 18. 1098 | * 1099 | * WARNING: This function should only be called from the constructor. Most 1100 | * applications that interact with token contracts will not expect 1101 | * {decimals} to ever change, and may work incorrectly if it does. 1102 | */ 1103 | function _setupDecimals(uint8 decimals_) internal { 1104 | _decimals = decimals_; 1105 | } 1106 | 1107 | /** 1108 | * @dev Hook that is called before any transfer of tokens. This includes 1109 | * minting and burning. 1110 | * 1111 | * Calling conditions: 1112 | * 1113 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 1114 | * will be to transferred to `to`. 1115 | * - when `from` is zero, `amount` tokens will be minted for `to`. 1116 | * - when `to` is zero, `amount` of ``from``'s tokens will be burned. 1117 | * - `from` and `to` are never both zero. 1118 | * 1119 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 1120 | */ 1121 | function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } 1122 | } 1123 | 1124 | // File: contracts/ONEPOOL.sol 1125 | 1126 | // File: @openzeppelin/contracts/GSN/Context.sol 1127 | 1128 | 1129 | 1130 | pragma solidity ^0.6.12; 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 1137 | 1138 | 1139 | /** 1140 | * @dev Implementation of the {IERC20} interface. 1141 | * 1142 | * This implementation is agnostic to the way tokens are created. This means 1143 | * that a supply mechanism has to be added in a derived contract using {_mint}. 1144 | * For a generic mechanism see {ERC20PresetMinterPauser}. 1145 | * 1146 | * TIP: For a detailed writeup see our guide 1147 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 1148 | * to implement supply mechanisms]. 1149 | * 1150 | * We have followed general OpenZeppelin guidelines: functions revert instead 1151 | * of returning `false` on failure. This behavior is nonetheless conventional 1152 | * and does not conflict with the expectations of ERC20 applications. 1153 | * 1154 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 1155 | * This allows applications to reconstruct the allowance for all accounts just 1156 | * by listening to said events. Other implementations of the EIP may not emit 1157 | * these events, as it isn't required by the specification. 1158 | * 1159 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 1160 | * functions have been added to mitigate the well-known issues around setting 1161 | * allowances. See {IERC20-approve}. 1162 | */ 1163 | contract ERC20Basic is Context, IERC20 , Ownable{ 1164 | using SafeMath for uint256; 1165 | using Address for address; 1166 | 1167 | mapping (address => uint256) private _balances; 1168 | 1169 | mapping (address => mapping (address => uint256)) private _allowances; 1170 | 1171 | uint256 private _totalSupply; 1172 | 1173 | string private _name; 1174 | string private _symbol; 1175 | uint8 private _decimals; 1176 | 1177 | 1178 | // A record of each accounts delegate 1179 | mapping (address => address) internal _delegates; 1180 | 1181 | /// @notice A checkpoint for marking number of votes from a given block 1182 | struct Checkpoint { 1183 | uint32 fromBlock; 1184 | uint256 votes; 1185 | } 1186 | 1187 | /// @notice A record of votes checkpoints for each account, by index 1188 | mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; 1189 | 1190 | /// @notice The number of checkpoints for each account 1191 | mapping (address => uint32) public numCheckpoints; 1192 | 1193 | /// @notice The EIP-712 typehash for the contract's domain 1194 | bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); 1195 | 1196 | /// @notice The EIP-712 typehash for the delegation struct used by the contract 1197 | bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); 1198 | 1199 | /// @notice A record of states for signing / validating signatures 1200 | mapping (address => uint) public nonces; 1201 | 1202 | /// @notice An event thats emitted when an account changes its delegate 1203 | event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); 1204 | 1205 | /// @notice An event thats emitted when a delegate account's vote balance changes 1206 | event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance); 1207 | 1208 | 1209 | /** 1210 | * @dev Sets the values for {name} and {symbol}, initializes {decimals} with 1211 | * a default value of 18. 1212 | * 1213 | * To select a different value for {decimals}, use {_setupDecimals}. 1214 | * 1215 | * All three of these values are immutable: they can only be set once during 1216 | * construction. 1217 | */ 1218 | constructor (string memory name, string memory symbol) public { 1219 | _name = name; 1220 | _symbol = symbol; 1221 | _decimals = 18; 1222 | } 1223 | 1224 | /** 1225 | * @dev Returns the name of the token. 1226 | */ 1227 | function name() public view returns (string memory) { 1228 | return _name; 1229 | } 1230 | 1231 | /** 1232 | * @dev Returns the symbol of the token, usually a shorter version of the 1233 | * name. 1234 | */ 1235 | function symbol() public view returns (string memory) { 1236 | return _symbol; 1237 | } 1238 | 1239 | /** 1240 | * @dev Returns the number of decimals used to get its user representation. 1241 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 1242 | * be displayed to a user as `5,05` (`505 / 10 ** 2`). 1243 | * 1244 | * Tokens usually opt for a value of 18, imitating the relationship between 1245 | * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is 1246 | * called. 1247 | * 1248 | * NOTE: This information is only used for _display_ purposes: it in 1249 | * no way affects any of the arithmetic of the contract, including 1250 | * {IERC20-balanceOf} and {IERC20-transfer}. 1251 | */ 1252 | function decimals() public view returns (uint8) { 1253 | return _decimals; 1254 | } 1255 | 1256 | /** 1257 | * @dev See {IERC20-totalSupply}. 1258 | */ 1259 | function totalSupply() public view override returns (uint256) { 1260 | return _totalSupply; 1261 | } 1262 | 1263 | function balanceOf(address account) public view override returns (uint256) { 1264 | return _balances[account]; 1265 | } 1266 | 1267 | 1268 | /** 1269 | * @dev See {IERC20-transfer}. 1270 | * 1271 | * Requirements: 1272 | * 1273 | * - `recipient` cannot be the zero address. 1274 | * - the caller must have a balance of at least `amount`. 1275 | */ 1276 | function transfer(address recipient, uint256 amount) public virtual override returns (bool) { 1277 | _transfer(_msgSender(), recipient, amount); 1278 | return true; 1279 | } 1280 | 1281 | /** 1282 | * @dev See {IERC20-allowance}. 1283 | */ 1284 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 1285 | return _allowances[owner][spender]; 1286 | } 1287 | 1288 | /** 1289 | * @dev See {IERC20-approve}. 1290 | * 1291 | * Requirements: 1292 | * 1293 | * - `spender` cannot be the zero address. 1294 | */ 1295 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 1296 | _approve(_msgSender(), spender, amount); 1297 | return true; 1298 | } 1299 | 1300 | /** 1301 | * @dev See {IERC20-transferFrom}. 1302 | * 1303 | * Emits an {Approval} event indicating the updated allowance. This is not 1304 | * required by the EIP. See the note at the beginning of {ERC20}; 1305 | * 1306 | * Requirements: 1307 | * - `sender` and `recipient` cannot be the zero address. 1308 | * - `sender` must have a balance of at least `amount`. 1309 | * - the caller must have allowance for ``sender``'s tokens of at least 1310 | * `amount`. 1311 | */ 1312 | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { 1313 | _transfer(sender, recipient, amount); 1314 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 1315 | return true; 1316 | } 1317 | 1318 | /** 1319 | * @dev Atomically increases the allowance granted to `spender` by the caller. 1320 | * 1321 | * This is an alternative to {approve} that can be used as a mitigation for 1322 | * problems described in {IERC20-approve}. 1323 | * 1324 | * Emits an {Approval} event indicating the updated allowance. 1325 | * 1326 | * Requirements: 1327 | * 1328 | * - `spender` cannot be the zero address. 1329 | */ 1330 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 1331 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 1332 | return true; 1333 | } 1334 | 1335 | /** 1336 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 1337 | * 1338 | * This is an alternative to {approve} that can be used as a mitigation for 1339 | * problems described in {IERC20-approve}. 1340 | * 1341 | * Emits an {Approval} event indicating the updated allowance. 1342 | * 1343 | * Requirements: 1344 | * 1345 | * - `spender` cannot be the zero address. 1346 | * - `spender` must have allowance for the caller of at least 1347 | * `subtractedValue`. 1348 | */ 1349 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 1350 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 1351 | return true; 1352 | } 1353 | 1354 | /** 1355 | * @dev Moves tokens `amount` from `sender` to `recipient`. 1356 | * 1357 | * This is internal function is equivalent to {transfer}, and can be used to 1358 | * e.g. implement automatic token fees, slashing mechanisms, etc. 1359 | * 1360 | * Emits a {Transfer} event. 1361 | * 1362 | * Requirements: 1363 | * 1364 | * - `sender` cannot be the zero address. 1365 | * - `recipient` cannot be the zero address. 1366 | * - `sender` must have a balance of at least `amount`. 1367 | */ 1368 | function _transfer(address sender, address recipient, uint256 amount) internal virtual { 1369 | require(sender != address(0), "ERC20: transfer from the zero address"); 1370 | require(recipient != address(0), "ERC20: transfer to the zero address"); 1371 | 1372 | _beforeTokenTransfer(sender, recipient, amount); 1373 | 1374 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 1375 | _balances[recipient] = _balances[recipient].add(amount); 1376 | _moveDelegates(_delegates[sender], _delegates[recipient], amount); 1377 | emit Transfer(sender, recipient, amount); 1378 | } 1379 | 1380 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 1381 | * the total supply. 1382 | * 1383 | * Emits a {Transfer} event with `from` set to the zero address. 1384 | * 1385 | * Requirements 1386 | * 1387 | * - `to` cannot be the zero address. 1388 | */ 1389 | function _mint(address account, uint256 amount) internal virtual { 1390 | require(account != address(0), "ERC20: mint to the zero address"); 1391 | 1392 | _beforeTokenTransfer(address(0), account, amount); 1393 | 1394 | _totalSupply = _totalSupply.add(amount); 1395 | _balances[account] = _balances[account].add(amount); 1396 | _moveDelegates(address(0), _delegates[account], amount); 1397 | emit Transfer(address(0), account, amount); 1398 | } 1399 | 1400 | /** 1401 | * @dev Destroys `amount` tokens from `account`, reducing the 1402 | * total supply. 1403 | * 1404 | * Emits a {Transfer} event with `to` set to the zero address. 1405 | * 1406 | * Requirements 1407 | * 1408 | * - `account` cannot be the zero address. 1409 | * - `account` must have at least `amount` tokens. 1410 | */ 1411 | function _burn(address account, uint256 amount) internal virtual { 1412 | require(account != address(0), "ERC20: burn from the zero address"); 1413 | 1414 | _beforeTokenTransfer(account, address(0), amount); 1415 | 1416 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 1417 | _totalSupply = _totalSupply.sub(amount); 1418 | emit Transfer(account, address(0), amount); 1419 | } 1420 | 1421 | 1422 | 1423 | 1424 | /** 1425 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 1426 | * 1427 | * This is internal function is equivalent to `approve`, and can be used to 1428 | * e.g. set automatic allowances for certain subsystems, etc. 1429 | * 1430 | * Emits an {Approval} event. 1431 | * 1432 | * Requirements: 1433 | * 1434 | * - `owner` cannot be the zero address. 1435 | * - `spender` cannot be the zero address. 1436 | */ 1437 | function _approve(address owner, address spender, uint256 amount) internal virtual { 1438 | require(owner != address(0), "ERC20: approve from the zero address"); 1439 | require(spender != address(0), "ERC20: approve to the zero address"); 1440 | 1441 | _allowances[owner][spender] = amount; 1442 | emit Approval(owner, spender, amount); 1443 | } 1444 | 1445 | /** 1446 | * @dev Sets {decimals} to a value other than the default one of 18. 1447 | * 1448 | * WARNING: This function should only be called from the constructor. Most 1449 | * applications that interact with token contracts will not expect 1450 | * {decimals} to ever change, and may work incorrectly if it does. 1451 | */ 1452 | function _setupDecimals(uint8 decimals_) internal { 1453 | _decimals = decimals_; 1454 | } 1455 | 1456 | 1457 | function _delegate(address delegator, address delegatee) 1458 | internal 1459 | { 1460 | address currentDelegate = _delegates[delegator]; 1461 | uint256 delegatorBalance = balanceOf(delegator); // balance of underlying (not scaled); 1462 | _delegates[delegator] = delegatee; 1463 | 1464 | emit DelegateChanged(delegator, currentDelegate, delegatee); 1465 | 1466 | _moveDelegates(currentDelegate, delegatee, delegatorBalance); 1467 | } 1468 | 1469 | function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal { 1470 | if (srcRep != dstRep && amount > 0) { 1471 | if (srcRep != address(0)) { 1472 | // decrease old representative 1473 | uint32 srcRepNum = numCheckpoints[srcRep]; 1474 | uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; 1475 | uint256 srcRepNew = srcRepOld.sub(amount); 1476 | _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); 1477 | } 1478 | 1479 | if (dstRep != address(0)) { 1480 | // increase new representative 1481 | uint32 dstRepNum = numCheckpoints[dstRep]; 1482 | uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; 1483 | uint256 dstRepNew = dstRepOld.add(amount); 1484 | _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); 1485 | } 1486 | } 1487 | } 1488 | 1489 | function _writeCheckpoint( 1490 | address delegatee, 1491 | uint32 nCheckpoints, 1492 | uint256 oldVotes, 1493 | uint256 newVotes 1494 | ) 1495 | internal 1496 | { 1497 | uint32 blockNumber = safe32(block.number, "_writeCheckpoint: block number exceeds 32 bits"); 1498 | 1499 | if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { 1500 | checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; 1501 | } else { 1502 | checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); 1503 | numCheckpoints[delegatee] = nCheckpoints + 1; 1504 | } 1505 | 1506 | emit DelegateVotesChanged(delegatee, oldVotes, newVotes); 1507 | } 1508 | 1509 | function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { 1510 | require(n < 2**32, errorMessage); 1511 | return uint32(n); 1512 | } 1513 | 1514 | function getChainId() internal pure returns (uint) { 1515 | uint256 chainId; 1516 | assembly { chainId := chainid() } 1517 | return chainId; 1518 | } 1519 | /** 1520 | * @dev Hook that is called before any transfer of tokens. This includes 1521 | * minting and burning. 1522 | * 1523 | * Calling conditions: 1524 | * 1525 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 1526 | * will be to transferred to `to`. 1527 | * - when `from` is zero, `amount` tokens will be minted for `to`. 1528 | * - when `to` is zero, `amount` of ``from``'s tokens will be burned. 1529 | * - `from` and `to` are never both zero. 1530 | * 1531 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 1532 | */ 1533 | function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } 1534 | } 1535 | 1536 | 1537 | // Token with Governance. 1538 | contract ONEPOOL is ERC20Basic { 1539 | 1540 | //Initialize Token name, symbol, decimal and totalsupply 1541 | constructor () public ERC20Basic ("oneToken", "op") { 1542 | 1543 | } 1544 | 1545 | /** 1546 | * @dev Burns a specific amount of tokens. Can be executed by contract Operator only. 1547 | * @param _value The amount of token to be burned. 1548 | */ 1549 | 1550 | function burn(uint256 _value) public onlyOwner { 1551 | _burn(msg.sender,_value); 1552 | } 1553 | 1554 | function mint(address _account, uint256 _value) public onlyOwner returns(bool) { 1555 | _mint(_account, _value); 1556 | return true; 1557 | } 1558 | 1559 | /** 1560 | * @notice Delegate votes from `msg.sender` to `delegatee` 1561 | * @param delegator The address to get delegatee for 1562 | */ 1563 | function delegates(address delegator) 1564 | external 1565 | view 1566 | returns (address) 1567 | { 1568 | return _delegates[delegator]; 1569 | } 1570 | 1571 | /** 1572 | * @notice Delegate votes from `msg.sender` to `delegatee` 1573 | * @param delegatee The address to delegate votes to 1574 | */ 1575 | function delegate(address delegatee) external { 1576 | return _delegate(msg.sender, delegatee); 1577 | } 1578 | 1579 | /** 1580 | * @notice Delegates votes from signatory to `delegatee` 1581 | * @param delegatee The address to delegate votes to 1582 | * @param nonce The contract state required to match the signature 1583 | * @param expiry The time at which to expire the signature 1584 | * @param v The recovery byte of the signature 1585 | * @param r Half of the ECDSA signature pair 1586 | * @param s Half of the ECDSA signature pair 1587 | */ 1588 | function delegateBySig( 1589 | address delegatee, 1590 | uint nonce, 1591 | uint expiry, 1592 | uint8 v, 1593 | bytes32 r, 1594 | bytes32 s 1595 | ) 1596 | external 1597 | 1598 | { 1599 | bytes32 domainSeparator = keccak256( 1600 | abi.encode( 1601 | DOMAIN_TYPEHASH, 1602 | keccak256(bytes(name())), 1603 | getChainId(), 1604 | address(this) 1605 | ) 1606 | ); 1607 | 1608 | bytes32 structHash = keccak256( 1609 | abi.encode( 1610 | DELEGATION_TYPEHASH, 1611 | delegatee, 1612 | nonce, 1613 | expiry 1614 | ) 1615 | ); 1616 | 1617 | bytes32 digest = keccak256( 1618 | abi.encodePacked( 1619 | "\x19\x01", 1620 | domainSeparator, 1621 | structHash 1622 | ) 1623 | ); 1624 | 1625 | address signatory = ecrecover(digest, v, r, s); 1626 | require(signatory != address(0), "delegateBySig: invalid signature"); 1627 | require(nonce == nonces[signatory]++, "delegateBySig: invalid nonce"); 1628 | require(now <= expiry, "delegateBySig: signature expired"); 1629 | return _delegate(signatory, delegatee); 1630 | } 1631 | 1632 | /** 1633 | * @notice Gets the current votes balance for `account` 1634 | * @param account The address to get votes balance 1635 | * @return The number of current votes for `account` 1636 | */ 1637 | function getCurrentVotes(address account) 1638 | external 1639 | view 1640 | returns (uint256) 1641 | { 1642 | uint32 nCheckpoints = numCheckpoints[account]; 1643 | return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; 1644 | } 1645 | 1646 | /** 1647 | * @notice Determine the prior number of votes for an account as of a block number 1648 | * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. 1649 | * @param account The address of the account to check 1650 | * @param blockNumber The block number to get the vote balance at 1651 | * @return The number of votes the account had as of the given block 1652 | */ 1653 | function getPriorVotes(address account, uint blockNumber) 1654 | external 1655 | view 1656 | returns (uint256) 1657 | { 1658 | require(blockNumber < block.number, "getPriorVotes: not yet determined"); 1659 | 1660 | uint32 nCheckpoints = numCheckpoints[account]; 1661 | if (nCheckpoints == 0) { 1662 | return 0; 1663 | } 1664 | 1665 | // First check most recent balance 1666 | if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { 1667 | return checkpoints[account][nCheckpoints - 1].votes; 1668 | } 1669 | 1670 | // Next check implicit zero balance 1671 | if (checkpoints[account][0].fromBlock > blockNumber) { 1672 | return 0; 1673 | } 1674 | 1675 | uint32 lower = 0; 1676 | uint32 upper = nCheckpoints - 1; 1677 | while (upper > lower) { 1678 | uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow 1679 | Checkpoint memory cp = checkpoints[account][center]; 1680 | if (cp.fromBlock == blockNumber) { 1681 | return cp.votes; 1682 | } else if (cp.fromBlock < blockNumber) { 1683 | lower = center; 1684 | } else { 1685 | upper = center - 1; 1686 | } 1687 | } 1688 | return checkpoints[account][lower].votes; 1689 | } 1690 | 1691 | 1692 | } 1693 | 1694 | // File: contracts/RewardPool.sol 1695 | 1696 | // File: @openzeppelin/contracts/token/ERC20/IERC20.sol 1697 | 1698 | 1699 | pragma solidity 0.6.12; 1700 | 1701 | 1702 | 1703 | 1704 | 1705 | 1706 | 1707 | interface IMaster{ 1708 | function deposit(uint256 _pid, uint256 _amount) external; 1709 | function withdraw(uint256 _pid, uint256 _amount) external; 1710 | function updatePool(uint256 _pid) external ; 1711 | function poolInfo(uint256 _pid) external view returns(address, uint256, uint256 , uint256); 1712 | function userInfo(uint256 _pid,address _user) external view returns(uint256, uint256); 1713 | function getMultiplier(uint256 _from, uint256 _to) external view returns (uint256); 1714 | function sushiPerBlock() external view returns(uint256); 1715 | function pendingSushi(uint256 _pid, address _user) external view returns(uint256); 1716 | function totalAllocPoint() external view returns(uint256); 1717 | function emergencyWithdraw(uint256 _pid) external ; 1718 | } 1719 | 1720 | 1721 | /** 1722 | * @dev Contract module which provides a basic access control mechanism, where 1723 | * there is an account (an owner) that can be granted exclusive access to 1724 | * specific functions. 1725 | * 1726 | * By default, the owner account will be the one that deploys the contract. This 1727 | * can later be changed with {transferOwnership}. 1728 | * 1729 | * This module is used through inheritance. It will make available the modifier 1730 | * `onlyOwner`, which can be applied to your functions to restrict their use to 1731 | * the owner. 1732 | */ 1733 | contract FactoryOwnable is Context { 1734 | address private _owner; 1735 | 1736 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 1737 | 1738 | /** 1739 | * @dev Initializes the contract setting the deployer as the initial owner. 1740 | */ 1741 | constructor (address owner) internal { 1742 | _owner = owner; 1743 | emit OwnershipTransferred(address(0), _owner); 1744 | } 1745 | 1746 | /** 1747 | * @dev Returns the address of the current owner. 1748 | */ 1749 | function owner() public view returns (address) { 1750 | return _owner; 1751 | } 1752 | 1753 | /** 1754 | * @dev Throws if called by any account other than the owner. 1755 | */ 1756 | modifier onlyOwner() { 1757 | require(_owner == _msgSender(), "Ownable: caller is not the owner"); 1758 | _; 1759 | } 1760 | 1761 | 1762 | /** 1763 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 1764 | * Can only be called by the current owner. 1765 | */ 1766 | function transferOwnership(address newOwner) public virtual onlyOwner { 1767 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 1768 | emit OwnershipTransferred(_owner, newOwner); 1769 | _owner = newOwner; 1770 | } 1771 | } 1772 | 1773 | 1774 | // File: contracts/RewardPool.sol 1775 | contract RewardPoolFactory is FactoryOwnable { 1776 | 1777 | using SafeMath for uint256; 1778 | using SafeERC20 for IERC20; 1779 | // Info of each user. 1780 | struct UserInfo { 1781 | uint256 amount; // How many LP tokens the user has provided. 1782 | uint256 rewardDebt; // Reward debt. 1783 | uint256 debt; //Yield reward 1784 | } 1785 | uint256 public poolId; 1786 | uint256 public lpId; 1787 | address public masterChef; 1788 | address public token; 1789 | uint256 public totalSupply; 1790 | bool public vaultStatus; 1791 | 1792 | // Info of each user that stakes LP tokens. 1793 | mapping(address => UserInfo) public userInfo; 1794 | 1795 | event Deposit(address indexed user, uint256 indexed pid, uint256 amount); 1796 | event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); 1797 | event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); 1798 | event SetVaultStatus(address sender, bool newStatus); 1799 | 1800 | RewardPool public rewardPool; 1801 | ONEPOOL public onePool; 1802 | 1803 | constructor(RewardPool _rewardPool,ONEPOOL _onePool, uint256 _poolId,uint256 _lpId,address _masterChef, address _token, bool _status, address _owner) 1804 | public FactoryOwnable(_owner) { 1805 | rewardPool = _rewardPool; 1806 | onePool = _onePool; 1807 | poolId = _poolId; 1808 | lpId = _lpId; 1809 | masterChef = _masterChef; 1810 | token = _token; 1811 | vaultStatus = _status; 1812 | } 1813 | 1814 | // Deposit LP tokens to MasterChef for onePool allocation. 1815 | function deposit( uint256 _amount) public { 1816 | rewardPool.updatePool(poolId); 1817 | (IERC20 lpToken, , , uint256 acconePoolPerShare,) = rewardPool.poolInfo(poolId); 1818 | UserInfo storage user = userInfo[msg.sender]; 1819 | 1820 | if (user.amount > 0) { 1821 | uint256 pending = user.amount.mul(acconePoolPerShare).div(1e12).sub( user.rewardDebt ); 1822 | if(pending > 0){ 1823 | user.rewardDebt = user.amount.mul(acconePoolPerShare).div(1e12); 1824 | safeonePoolTransfer(msg.sender, pending); 1825 | } 1826 | } 1827 | if(_amount>0){ 1828 | lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); 1829 | } 1830 | if(vaultStatus == true){ 1831 | yieldDeposit(lpToken.balanceOf(address(this)), user, lpToken); 1832 | } 1833 | 1834 | if(_amount > 0){ 1835 | user.amount = user.amount.add(_amount); 1836 | totalSupply = totalSupply.add(_amount); 1837 | } 1838 | user.rewardDebt = user.amount.mul(acconePoolPerShare).div(1e12); 1839 | emit Deposit(msg.sender, poolId, _amount); 1840 | 1841 | } 1842 | 1843 | function yieldDeposit(uint256 _amount, UserInfo memory user, IERC20 lpToken) internal { 1844 | lpToken.approve(masterChef, _amount); 1845 | IMaster(masterChef).deposit(lpId,_amount); // move lptoken to masterchef 1846 | uint256 accYieldPerShare = poolDetails(lpId); 1847 | if (user.amount > 0) { 1848 | uint256 pendinglp = user.amount.mul(accYieldPerShare).div(1e12).sub(user.debt); 1849 | if(pendinglp > 0){ 1850 | user.debt = user.amount.mul(accYieldPerShare).div(1e12); 1851 | safeYieldTransfer(msg.sender, pendinglp); 1852 | } 1853 | } 1854 | user.debt = user.amount.mul(accYieldPerShare).div(1e12); 1855 | } 1856 | 1857 | 1858 | // Withdraw LP tokens from MasterChef. 1859 | function withdraw(uint256 _amount) public { 1860 | UserInfo storage user = userInfo[msg.sender]; 1861 | require(user.amount >= _amount && _amount > 0, "withdraw: not good"); 1862 | rewardPool.updatePool(poolId); 1863 | 1864 | (IERC20 lpToken, , , uint256 acconePoolPerShare,) = rewardPool.poolInfo(poolId); 1865 | uint256 pending = user.amount.mul(acconePoolPerShare).div(1e12).sub(user.rewardDebt); 1866 | if(pending > 0){ 1867 | safeonePoolTransfer(msg.sender, pending); 1868 | } 1869 | 1870 | if(vaultStatus == true){ 1871 | yieldWithdraw(_amount, user); 1872 | } 1873 | 1874 | user.amount = user.amount.sub(_amount); 1875 | totalSupply = totalSupply.sub(_amount); 1876 | user.rewardDebt = user.amount.mul(acconePoolPerShare).div(1e12); 1877 | 1878 | lpToken.safeTransfer(address(msg.sender), _amount); 1879 | 1880 | emit Withdraw(msg.sender, poolId, _amount); 1881 | } 1882 | 1883 | function yieldWithdraw(uint256 _amount, UserInfo memory user) internal { 1884 | (IERC20 lpToken, , , ,) = rewardPool.poolInfo(poolId); 1885 | if(lpToken.balanceOf(address(this)) < _amount){ 1886 | IMaster(masterChef).withdraw(lpId,_amount); 1887 | } 1888 | uint accYieldPerShare = poolDetails(lpId); 1889 | uint256 pendinglp = user.amount.mul(accYieldPerShare).div(1e12).sub(user.debt); 1890 | if(pendinglp > 0){ 1891 | safeYieldTransfer(msg.sender, pendinglp); 1892 | } 1893 | user.debt = user.amount.mul(accYieldPerShare).div(1e12); 1894 | } 1895 | 1896 | // Withdraw without caring about rewards. EMERGENCY ONLY. 1897 | function emergencyWithdraw() public { 1898 | (IERC20 lpToken, , , ,) = rewardPool.poolInfo(poolId); 1899 | UserInfo storage user = userInfo[msg.sender]; 1900 | uint256 amount = user.amount; 1901 | user.amount = 0; 1902 | user.rewardDebt = 0; 1903 | user.debt = 0; 1904 | totalSupply = totalSupply.sub(amount); 1905 | if( (vaultStatus == true) && (lpToken.balanceOf(address(this)) < amount) ){ 1906 | IMaster(masterChef).withdraw(lpId,amount); 1907 | } 1908 | lpToken.safeTransfer(address(msg.sender), amount); 1909 | emit EmergencyWithdraw(msg.sender, poolId, amount); 1910 | 1911 | } 1912 | 1913 | // Safe onePool transfer function, just in case if rounding error causes pool to not have enough 1Pool. 1914 | function safeonePoolTransfer(address _to, uint256 _amount) internal { 1915 | uint256 onePoolBal = onePool.balanceOf(address(this)); 1916 | if (_amount > onePoolBal) { 1917 | onePool.transfer(_to, onePoolBal); 1918 | } else { 1919 | onePool.transfer(_to, _amount); 1920 | } 1921 | } 1922 | 1923 | function safeYieldTransfer(address _to, uint256 _amount) internal { 1924 | 1925 | uint256 bal = IERC20(token).balanceOf(address(this)); 1926 | if(bal < _amount){ 1927 | _amount = bal; 1928 | } 1929 | if(_amount > 0) { 1930 | uint256 treasuryFund = _amount.mul(rewardPool.treasuryPcent()).div(100); 1931 | uint256 stakerFund = _amount.mul(rewardPool.stakePcent()).div(100); 1932 | _amount = _amount.mul(rewardPool.yieldPcent()).div(100); 1933 | IERC20(token).safeTransfer(_to, _amount); // user reward 1934 | if( (rewardPool.stake() != address(0)) && (stakerFund > 0 ) ){ 1935 | IERC20(token).safeTransfer(rewardPool.stake(), stakerFund); // stakingHolder reward 1936 | } 1937 | if( (rewardPool.treasury() != address(0)) && (treasuryFund > 0) ){ 1938 | IERC20(token).safeTransfer(rewardPool.treasury(),treasuryFund); // treasury reward 1939 | } 1940 | } 1941 | } 1942 | 1943 | function emergencyWithReward() external onlyOwner { 1944 | if(vaultStatus){ 1945 | (IERC20 lpToken, , , ,) = rewardPool.poolInfo(poolId); 1946 | IMaster(masterChef).withdraw(lpId, totalSupply); 1947 | vaultStatus = false; 1948 | emit EmergencyWithdraw(address(this), poolId, totalSupply); 1949 | } 1950 | } 1951 | 1952 | function emergency() external onlyOwner { 1953 | if(vaultStatus){ 1954 | IMaster(masterChef).emergencyWithdraw(lpId); 1955 | vaultStatus = false; 1956 | } 1957 | } 1958 | 1959 | function setVaultStatus(bool _status) external onlyOwner { 1960 | require(vaultStatus != _status , "invalid status"); 1961 | (IERC20 lpToken, , , ,) = rewardPool.poolInfo(poolId); 1962 | if(vaultStatus){ 1963 | IMaster(masterChef).emergencyWithdraw(lpId); 1964 | } 1965 | vaultStatus = _status; 1966 | emit SetVaultStatus(msg.sender, _status); 1967 | } 1968 | 1969 | // View function to see pending 1Pool on frontend. 1970 | function pendingonePool(address _user) public view returns (uint256) { 1971 | ( , uint256 allocPoint, uint256 lastRewardBlock, uint256 acconePoolPerShare, ) = rewardPool.poolInfo(poolId); 1972 | UserInfo storage user = userInfo[_user]; 1973 | uint256 _acconePoolPerShare = acconePoolPerShare; 1974 | uint256 lpSupply = totalSupply; 1975 | if (block.number > lastRewardBlock && lpSupply != 0) { 1976 | uint256 multiplier = 1977 | rewardPool.getMultiplier(lastRewardBlock, block.number); 1978 | uint256 onePoolReward = 1979 | multiplier.mul(rewardPool.onePoolPerBlock()).mul(allocPoint).div( 1980 | rewardPool.totalAllocPoint() 1981 | ); 1982 | onePoolReward = onePoolReward.sub(onePoolReward.div(10)); 1983 | _acconePoolPerShare = _acconePoolPerShare.add( 1984 | onePoolReward.mul(1e12).div(lpSupply) 1985 | ); 1986 | } 1987 | return user.amount.mul(_acconePoolPerShare).div(1e12).sub(user.rewardDebt); 1988 | } 1989 | 1990 | function rewardpool()external view returns(address){ 1991 | return address(rewardPool); 1992 | } 1993 | 1994 | function poolDetails(uint _poolId) public view returns(uint poolAccPerShare){ 1995 | ( , , , poolAccPerShare) = IMaster(masterChef).poolInfo(_poolId); 1996 | } 1997 | 1998 | function getyieldReward(address _user) external view returns(uint pendinglp){ 1999 | if (vaultStatus == true){ 2000 | UserInfo storage user = userInfo[_user]; 2001 | ( address lpToken, uint256 allocPoint, uint256 lastRewardBlock, uint256 yieldPerShare) = getPoolDetails(lpId); 2002 | 2003 | uint256 lpSupply = IERC20(lpToken).balanceOf(masterChef); 2004 | 2005 | uint256 multiplier = IMaster(masterChef).getMultiplier(lastRewardBlock, block.number); 2006 | uint256 sushiReward = multiplier.mul(IMaster(masterChef).sushiPerBlock()).mul(allocPoint).div(IMaster(masterChef).totalAllocPoint()); 2007 | uint accSushiPerShare = yieldPerShare.add(sushiReward.mul(1e12).div(lpSupply)); 2008 | pendinglp = user.amount.mul(accSushiPerShare).div(1e12).sub(user.debt); 2009 | return pendinglp.mul(rewardPool.yieldPcent()).div(100); 2010 | } 2011 | } 2012 | 2013 | function getRewardonePool(address _user) external view returns(uint _totalReward) { 2014 | _totalReward = pendingonePool(_user); 2015 | (, , , uint256 acconePoolPerShare,) = rewardPool.poolInfo(poolId); 2016 | UserInfo storage user = userInfo[_user]; 2017 | uint256 pending = user.amount.mul(acconePoolPerShare).div(1e12).sub(user.rewardDebt); 2018 | _totalReward = _totalReward + pending; 2019 | } 2020 | 2021 | function getPoolDetails(uint _poolId) public view returns(address lpToken, uint256 allocPoint, uint256 lastRewardBlock, uint256 poolAccPerShare){ 2022 | (lpToken ,allocPoint , lastRewardBlock, poolAccPerShare) = IMaster(masterChef).poolInfo(_poolId); 2023 | } 2024 | } 2025 | 2026 | 2027 | contract RewardPool is Ownable { 2028 | using SafeMath for uint256; 2029 | using SafeERC20 for IERC20; 2030 | 2031 | // Info of each pool. 2032 | struct PoolInfo { 2033 | IERC20 lpToken; // Address of LP token contract. 2034 | uint256 allocPoint; // How many allocation points assigned to this pool. 1Pool to distribute per block. 2035 | uint256 lastRewardBlock; // Last block number that 1Pool distribution occurs. 2036 | uint256 acconePoolPerShare; // Accumulated 1Pool per share, times 1e12. See below. 2037 | address reawardFactory; // lp staking contract address 2038 | } 2039 | // The onePool TOKEN! 2040 | ONEPOOL public onePool; 2041 | // onePool tokens created per block. 2042 | uint256 public onePoolPerBlock; 2043 | // Info of each pool. 2044 | PoolInfo[] public poolInfo; 2045 | // Total allocation poitns. Must be the sum of all allocation points in all pools. 2046 | uint256 public totalAllocPoint = 0; 2047 | // The block number when onePool mining starts. 2048 | uint256 public startBlock; 2049 | // The Masterchef address 2050 | address public masterChef; 2051 | // The yield reawrd token 2052 | address public token; 2053 | // One pool converter address 2054 | address public stake; 2055 | // The treasury address 2056 | address public treasury; 2057 | address public devaddr; 2058 | 2059 | uint256 public treasuryPcent = 5; // 5% 2060 | uint256 public stakePcent = 20; // 25% 2061 | uint256 public yieldPcent = 75; 2062 | 2063 | mapping(address => bool) public lpPoolStatus; 2064 | 2065 | event Deposit(address indexed user, uint256 indexed pid, uint256 amount); 2066 | event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); 2067 | event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); 2068 | event OnePoolPerBlock(uint256 value); 2069 | event SetTreasury(address newTreasury); 2070 | event SetStake(address stake); 2071 | event SetDev(address sender, address newdev); 2072 | event SetFeePcent(address sender, uint256 newTreasuryPcent, uint256 newStakingPcent, uint256 newYieldPcent); 2073 | 2074 | modifier lpPool(address _lpToken) { 2075 | require(lpPoolStatus[_lpToken] == false, "invalid"); 2076 | _; 2077 | } 2078 | 2079 | constructor(ONEPOOL _onePool, uint256 _onePoolPerBlock, uint256 _startBlock, address _masterChef, address _token, 2080 | address _tresary, address _convert, address _dev) public { 2081 | onePool = _onePool; 2082 | onePoolPerBlock = _onePoolPerBlock; 2083 | startBlock = _startBlock; 2084 | masterChef = _masterChef; 2085 | token = _token; 2086 | stake = _convert; 2087 | treasury = _tresary; 2088 | devaddr = _dev; 2089 | } 2090 | 2091 | function poolLength() public view returns (uint256) { 2092 | return poolInfo.length; 2093 | } 2094 | 2095 | // Add a new lp to the pool. Can only be called by the owner. 2096 | function add( uint256 _allocPoint,IERC20 _lpToken, bool _withUpdate, uint256 _lpId, bool _status) public onlyOwner { 2097 | require(lpPoolStatus[address(_lpToken)] == false, "duplicated"); 2098 | if (_withUpdate) { 2099 | massUpdatePools(); 2100 | } 2101 | uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock; 2102 | totalAllocPoint = totalAllocPoint.add(_allocPoint); 2103 | address _reawardFactory = address(new RewardPoolFactory(RewardPool(address(this)), onePool, poolLength(), _lpId, masterChef, token,_status, msg.sender)); 2104 | poolInfo.push( 2105 | PoolInfo({ 2106 | lpToken: _lpToken, 2107 | allocPoint: _allocPoint, 2108 | lastRewardBlock: lastRewardBlock, 2109 | acconePoolPerShare: 0, 2110 | reawardFactory: _reawardFactory 2111 | }) 2112 | ); 2113 | lpPoolStatus[address(_lpToken)] = true; 2114 | } 2115 | 2116 | // Update the given pool's onePool allocation point. Can only be called by the owner. 2117 | function set( uint256 _pid, uint256 _allocPoint, bool _withUpdate ) public onlyOwner { 2118 | require( _pid < poolLength(), "pool not exist"); 2119 | if (_withUpdate) { 2120 | massUpdatePools(); 2121 | } 2122 | totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add( 2123 | _allocPoint 2124 | ); 2125 | require(lpPoolStatus[address(poolInfo[_pid].lpToken)] == true, "invalid"); 2126 | poolInfo[_pid].allocPoint = _allocPoint; 2127 | } 2128 | 2129 | // Return reward multiplier over the given _from to _to block. 2130 | function getMultiplier(uint256 _from, uint256 _to) public pure returns (uint256) { 2131 | return _to.sub(_from); 2132 | } 2133 | 2134 | // Update reward vairables for all pools. Be careful of gas spending! 2135 | function massUpdatePools() public { 2136 | uint256 length = poolInfo.length; 2137 | for (uint256 pid = 0; pid < length; ++pid) { 2138 | updatePool(pid); 2139 | } 2140 | } 2141 | 2142 | // Update reward variables of the given pool to be up-to-date. 2143 | function updatePool(uint256 _pid) public { 2144 | require(lpPoolStatus[address(poolInfo[_pid].lpToken)] == true, "invalid"); 2145 | PoolInfo storage pool = poolInfo[_pid]; 2146 | 2147 | if (block.number <= pool.lastRewardBlock) { 2148 | return; 2149 | } 2150 | uint256 lpSupply = RewardPoolFactory(pool.reawardFactory).totalSupply(); 2151 | if (lpSupply == 0) { 2152 | pool.lastRewardBlock = block.number; 2153 | return; 2154 | } 2155 | uint256 multiplier = getMultiplier(pool.lastRewardBlock, block.number); 2156 | uint256 onePoolReward = 2157 | multiplier.mul(onePoolPerBlock).mul(pool.allocPoint).div( 2158 | totalAllocPoint 2159 | ); 2160 | onePool.mint(devaddr, onePoolReward.div(10)); 2161 | onePoolReward = onePoolReward.sub(onePoolReward.div(10)); 2162 | require(onePool.mint(pool.reawardFactory, onePoolReward)); 2163 | pool.acconePoolPerShare = pool.acconePoolPerShare.add( 2164 | onePoolReward.mul(1e12).div(lpSupply) 2165 | ); 2166 | pool.lastRewardBlock = block.number; 2167 | } 2168 | 2169 | // Safe onePool transfer function, just in case if rounding error causes pool to not have enough 1Pool. 2170 | function safeonePoolTransfer(address _to, uint256 _amount) internal { 2171 | uint256 onePoolBal = onePool.balanceOf(address(this)); 2172 | if (_amount > onePoolBal) { 2173 | onePool.transfer(_to, onePoolBal); 2174 | } else { 2175 | onePool.transfer(_to, _amount); 2176 | } 2177 | } 2178 | 2179 | function setONEPoolBlock(uint256 _amount) public onlyOwner { 2180 | massUpdatePools(); 2181 | onePoolPerBlock =_amount; 2182 | emit OnePoolPerBlock(_amount); 2183 | } 2184 | 2185 | function setTreasury(address _treasury) public onlyOwner { 2186 | treasury =_treasury; 2187 | emit SetTreasury(_treasury); 2188 | } 2189 | 2190 | function setStake(address _stake) public onlyOwner { 2191 | stake =_stake; 2192 | emit SetStake(_stake); 2193 | } 2194 | 2195 | // Update dev address by the previous dev. 2196 | function dev(address _devaddr) public { 2197 | require(msg.sender == devaddr, "dev: wut?"); 2198 | devaddr = _devaddr; 2199 | SetDev(msg.sender, _devaddr); 2200 | } 2201 | 2202 | function setFeePcent(uint256 _treasury, uint256 _stake) external onlyOwner { 2203 | require(_treasury.add(_stake) < 100 , "invalid fee"); 2204 | treasuryPcent = _treasury; 2205 | stakePcent = _stake; 2206 | yieldPcent = uint256(100).sub(treasuryPcent.add(_stake)); 2207 | emit SetFeePcent(msg.sender, treasuryPcent, stakePcent, yieldPcent); 2208 | } 2209 | 2210 | } 2211 | --------------------------------------------------------------------------------