Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 3,515 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Stake | 13486160 | 1129 days ago | IN | 1.2 ETH | 0.02296683 | ||||
Stake | 13302049 | 1158 days ago | IN | 1 ETH | 0.01583102 | ||||
Stake | 12982375 | 1207 days ago | IN | 0.3 ETH | 0.02126199 | ||||
Stake | 12873667 | 1224 days ago | IN | 0.3 ETH | 0.00804155 | ||||
Stake | 12575572 | 1271 days ago | IN | 0.12 ETH | 0.03540799 | ||||
Stake | 12512603 | 1280 days ago | IN | 0.05 ETH | 0.01083862 | ||||
Stake | 12512261 | 1280 days ago | IN | 0.35 ETH | 0.01678238 | ||||
Stake | 12486630 | 1284 days ago | IN | 0.5 ETH | 0.01305416 | ||||
Stake | 12459069 | 1289 days ago | IN | 2 ETH | 0.04033164 | ||||
Stake | 12453781 | 1290 days ago | IN | 0.12 ETH | 0.0350507 | ||||
Stake | 12434242 | 1293 days ago | IN | 2.5 ETH | 0.04133993 | ||||
Stake | 12374684 | 1302 days ago | IN | 0.85 ETH | 0.01961441 | ||||
Stake | 12363120 | 1304 days ago | IN | 1.826 ETH | 0.0332736 | ||||
Stake | 12339254 | 1307 days ago | IN | 0.35 ETH | 0.01176339 | ||||
Stake | 12265455 | 1319 days ago | IN | 1 ETH | 0.03892429 | ||||
Stake | 12240387 | 1323 days ago | IN | 5.22 ETH | 0.04914386 | ||||
Stake | 12239765 | 1323 days ago | IN | 5.25 ETH | 0.08190643 | ||||
Stake | 12220527 | 1326 days ago | IN | 1.25 ETH | 0.03000438 | ||||
Stake | 12209175 | 1327 days ago | IN | 1.491 ETH | 0.03549814 | ||||
Stake | 12172004 | 1333 days ago | IN | 1.5 ETH | 0.05006109 | ||||
Stake | 12082448 | 1347 days ago | IN | 6 ETH | 0.04995169 | ||||
Stake | 11944502 | 1368 days ago | IN | 0.3 ETH | 0.0418371 | ||||
Stake | 11863109 | 1381 days ago | IN | 0.1 ETH | 0.05608623 | ||||
Stake | 11856972 | 1382 days ago | IN | 0.37 ETH | 0.04006159 | ||||
Stake | 11853924 | 1382 days ago | IN | 0.0226556 ETH | 0.01817904 |
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
13486160 | 1129 days ago | 0.00664901 ETH | ||||
13486160 | 1129 days ago | 0.59335098 ETH | ||||
13486160 | 1129 days ago | 0.6 ETH | ||||
13302049 | 1158 days ago | 0.00570047 ETH | ||||
13302049 | 1158 days ago | 0.49429952 ETH | ||||
13302049 | 1158 days ago | 0.5 ETH | ||||
12982375 | 1207 days ago | 0.00190638 ETH | ||||
12982375 | 1207 days ago | 0.14809361 ETH | ||||
12982375 | 1207 days ago | 0.15 ETH | ||||
12873667 | 1224 days ago | 0.00191297 ETH | ||||
12873667 | 1224 days ago | 0.14808702 ETH | ||||
12873667 | 1224 days ago | 0.15 ETH | ||||
12575572 | 1271 days ago | 0.00077382 ETH | ||||
12575572 | 1271 days ago | 0.05922617 ETH | ||||
12575572 | 1271 days ago | 0.06 ETH | ||||
12512603 | 1280 days ago | 0.00032349 ETH | ||||
12512603 | 1280 days ago | 0.0246765 ETH | ||||
12512603 | 1280 days ago | 0.025 ETH | ||||
12512261 | 1280 days ago | 0.00223281 ETH | ||||
12512261 | 1280 days ago | 0.17276718 ETH | ||||
12512261 | 1280 days ago | 0.175 ETH | ||||
12486630 | 1284 days ago | 0.00316765 ETH | ||||
12486630 | 1284 days ago | 0.24683234 ETH | ||||
12486630 | 1284 days ago | 0.25 ETH | ||||
12459069 | 1289 days ago | 0.01178393 ETH |
Loading...
Loading
Contract Name:
AutoDeposit
Compiler Version
v0.6.12+commit.27d51765
Contract Source Code (Solidity Multiple files format)
pragma solidity ^0.6.12; import './IUniswapV2Router02.sol'; import './IUniswapV2Pair.sol'; import './SafeERC20.sol'; import './IERC20.sol'; import './Tito.sol'; import './Whirlpool.sol'; contract AutoDeposit { using SafeERC20 for IERC20; IUniswapV2Router02 internal uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); Tito internal tito; Whirlpool internal whirlpool; constructor(Tito _tito, Whirlpool _whirlpool) public { tito = _tito; whirlpool = _whirlpool; } receive() external payable { require(msg.sender != tx.origin); } function depositInto(uint256 _pid) external payable returns (uint256 lpReceived) { require(msg.value > 0 && _pid < tito.poolLength()); (IERC20 _token, IERC20 _pool, , , , , ) = tito.poolInfo(_pid); lpReceived = _convertToLP(_token, _pool, msg.value); _pool.safeApprove(address(tito), 0); _pool.safeApprove(address(tito), lpReceived); tito.depositFor(_pid, msg.sender, lpReceived); } function giveFor(uint256 _pid) external payable returns (uint256 lpReceived) { require(msg.value > 0 && _pid < tito.poolLength()); (IERC20 _token, IERC20 _pool, , , , , ) = tito.poolInfo(_pid); lpReceived = _convertToLP(_token, _pool, msg.value); _pool.transfer(msg.sender, lpReceived); } function stake() external payable returns (uint256 lpReceived) { require(msg.value > 0 && whirlpool.active()); lpReceived = _convertToLP(IERC20(whirlpool.surf()), whirlpool.surfPool(), msg.value); whirlpool.surfPool().safeApprove(address(whirlpool), 0); whirlpool.surfPool().safeApprove(address(whirlpool), lpReceived); whirlpool.stakeFor(msg.sender, lpReceived); } function _convertToLP(IERC20 _token, IERC20 _pool, uint256 _amount) internal returns (uint256) { require(_amount > 0); address[] memory _poolPath = new address[](2); _poolPath[0] = uniswapRouter.WETH(); _poolPath[1] = address(_token); uniswapRouter.swapExactETHForTokens{value: _amount / 2}(0, _poolPath, address(this), block.timestamp + 5 minutes); return _addLP(_token, _pool, _token.balanceOf(address(this)), address(this).balance); } function _addLP(IERC20 _token, IERC20 _pool, uint256 _tokens, uint256 _eth) internal returns (uint256 liquidityAdded) { require(_tokens > 0 && _eth > 0); IUniswapV2Pair _pair = IUniswapV2Pair(address(_pool)); (uint256 _reserve0, uint256 _reserve1, ) = _pair.getReserves(); bool _isToken0 = _pair.token0() == address(_token); uint256 _tokensPerETH = 1e18 * (_isToken0 ? _reserve0 : _reserve1) / (_isToken0 ? _reserve1 : _reserve0); _token.safeApprove(address(uniswapRouter), 0); if (_tokensPerETH > 1e18 * _tokens / _eth) { uint256 _ethValue = 1e18 * _tokens / _tokensPerETH; _token.safeApprove(address(uniswapRouter), _tokens); ( , , liquidityAdded) = uniswapRouter.addLiquidityETH{value: _ethValue}(address(_token), _tokens, 0, 0, address(this), block.timestamp + 5 minutes); } else { uint256 _tokenValue = 1e18 * _tokensPerETH / _eth; _token.safeApprove(address(uniswapRouter), _tokenValue); ( , , liquidityAdded) = uniswapRouter.addLiquidityETH{value: _eth}(address(_token), _tokenValue, 0, 0, address(this), block.timestamp + 5 minutes); } uint256 _remainingETH = address(this).balance; uint256 _remainingTokens = _token.balanceOf(address(this)); if (_remainingETH > 0) { msg.sender.transfer(_remainingETH); } if (_remainingTokens > 0) { _token.transfer(msg.sender, _remainingTokens); } } }
pragma solidity ^0.6.12; // File: @openzeppelin/contracts/utils/Address.sol /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
pragma solidity ^0.6.12; // File: @openzeppelin/contracts/GSN/Context.sol /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
pragma solidity ^0.6.12; import './Context.sol'; import './IERC20.sol'; import './SafeMath.sol'; // File: @openzeppelin/contracts/token/ERC20/ERC20.sol /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin guidelines: functions revert instead * of returning `false` on failure. This behavior is nonetheless conventional * and does not conflict with the expectations of ERC20 applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20 { using SafeMath for uint256; mapping (address => uint256) internal _balances; mapping (address => mapping (address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; uint8 private _decimals; /** * @dev Sets the values for {name} and {symbol}, initializes {decimals} with * a default value of 18. * * To select a different value for {decimals}, use {_setupDecimals}. * * All three of these values are immutable: they can only be set once during * construction. */ constructor (string memory name, string memory symbol) public { _name = name; _symbol = symbol; _decimals = 18; } /** * @dev Returns the name of the token. */ function name() public view returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5,05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is * called. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view override returns (uint8) { return _decimals; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `recipient` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address recipient, uint256 amount) public virtual override returns (bool) { _transfer(_msgSender(), recipient, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { _approve(_msgSender(), spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}; * * Requirements: * - `sender` and `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. * - the caller must have allowance for ``sender``'s tokens of at least * `amount`. */ function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { _transfer(sender, recipient, amount); _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } /** * @dev Moves tokens `amount` from `sender` to `recipient`. * * This is internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `sender` cannot be the zero address. * - `recipient` cannot be the zero address. * - `sender` must have a balance of at least `amount`. */ function _transfer(address sender, address recipient, uint256 amount) internal virtual { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(sender, recipient, amount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); _balances[recipient] = _balances[recipient].add(amount); emit Transfer(sender, recipient, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements * * - `to` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply = _totalSupply.add(amount); _balances[account] = _balances[account].add(amount); emit Transfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); _totalSupply = _totalSupply.sub(amount); emit Transfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. * * This is internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve(address owner, address spender, uint256 amount) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Sets {decimals} to a value other than the default one of 18. * * WARNING: This function should only be called from the constructor. Most * applications that interact with token contracts will not expect * {decimals} to ever change, and may work incorrectly if it does. */ function _setupDecimals(uint8 decimals_) internal { _decimals = decimals_; } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be to transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { } }
pragma solidity ^0.6.12; // File: @openzeppelin/contracts/token/ERC20/IERC20.sol /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the number of decimal places. */ function decimals() external view returns (uint8); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
pragma solidity ^0.6.12; interface IUniswapV2Pair { event Approval(address indexed owner, address indexed spender, uint value); event Transfer(address indexed from, address indexed to, uint value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint); function balanceOf(address owner) external view returns (uint); function allowance(address owner, address spender) external view returns (uint); function approve(address spender, uint value) external returns (bool); function transfer(address to, uint value) external returns (bool); function transferFrom(address from, address to, uint value) external returns (bool); function DOMAIN_SEPARATOR() external view returns (bytes32); function PERMIT_TYPEHASH() external pure returns (bytes32); function nonces(address owner) external view returns (uint); function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; event Mint(address indexed sender, uint amount0, uint amount1); event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); event Swap( address indexed sender, uint amount0In, uint amount1In, uint amount0Out, uint amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); function MINIMUM_LIQUIDITY() external pure returns (uint); function factory() external view returns (address); function token0() external view returns (address); function token1() external view returns (address); function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function kLast() external view returns (uint); function mint(address to) external returns (uint liquidity); function burn(address to) external returns (uint amount0, uint amount1); function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; function skim(address to) external; function sync() external; function initialize(address, address) external; }
pragma solidity ^0.6.12; // File: @uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint amountADesired, uint amountBDesired, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB, uint liquidity); function addLiquidityETH( address token, uint amountTokenDesired, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external payable returns (uint amountToken, uint amountETH, uint liquidity); function removeLiquidity( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline ) external returns (uint amountA, uint amountB); function removeLiquidityETH( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountToken, uint amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint liquidity, uint amountAMin, uint amountBMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountA, uint amountB); function removeLiquidityETHWithPermit( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountToken, uint amountETH); function swapExactTokensForTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapTokensForExactTokens( uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline ) external returns (uint[] memory amounts); function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts); function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts); function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB); function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut); function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn); function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline ) external returns (uint amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint liquidity, uint amountTokenMin, uint amountETHMin, address to, uint deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint amountOutMin, address[] calldata path, address to, uint deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external; }
pragma solidity ^0.6.12; import './Context.sol'; // File: @openzeppelin/contracts/access/Ownable.sol /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
pragma solidity ^0.6.12; import './SafeMath.sol'; import './Address.sol'; import './IERC20.sol'; // File: @openzeppelin/contracts/token/ERC20/SafeERC20.sol /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
pragma solidity ^0.6.12; // File: @openzeppelin/contracts/math/SafeMath.sol /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } }
/* _____ __ ______ ______ ___________ _____ _ ______________ / ___// / / / __ \/ ____/ / ____/ _/ | / / | / | / / ____/ ____/ \__ \/ / / / /_/ / /_ / /_ / // |/ / /| | / |/ / / / __/ ___/ / /_/ / _, _/ __/ _ / __/ _/ // /| / ___ |/ /| / /___/ /___ /____/\____/_/ |_/_/ (_) /_/ /___/_/ |_/_/ |_/_/ |_/\____/_____/ Website: https://surf.finance Created by Proof and sol_dev, with help from Zoma and Mr Fahrenheit Audited by Aegis DAO and Sherlock Security */ pragma solidity ^0.6.12; import './ERC20.sol'; import './IERC20.sol'; import './Ownable.sol'; import './Whirlpool.sol'; interface Callable { function tokenCallback(address _from, uint256 _tokens, bytes calldata _data) external returns (bool); function receiveApproval(address _from, uint256 _tokens, address _token, bytes calldata _data) external; } // SURF Token with Governance. The governance contract will own the SURF, Tito, and Whirlpool contracts, // allowing SURF token holders to make and vote on proposals that can modify many parts of the protocol. contract SURF is ERC20("SURF.Finance", "SURF"), Ownable { // There will be a max supply of 10,000,000 SURF tokens uint256 public constant MAX_SUPPLY = 10000000 * 10**18; bool public maxSupplyHit = false; // The SURF transfer fee that gets rewarded to Whirlpool stakers (1 = 0.1%). Defaults to 1% uint256 public transferFee = 10; // Mapping of whitelisted sender and recipient addresses that don't pay the transfer fee. Allows SURF token holders to whitelist future contracts mapping(address => bool) public senderWhitelist; mapping(address => bool) public recipientWhitelist; // The Tito contract address public titoAddress; // The Whirlpool contract address payable public whirlpoolAddress; // The Uniswap SURF-ETH LP token address address public surfPoolAddress; // Creates `_amount` token to `_to`. Can only be called by the Tito contract. function mint(address _to, uint256 _amount) public { require(maxSupplyHit != true, "max supply hit"); require(msg.sender == titoAddress, "not Tito"); uint256 supply = totalSupply(); if (supply.add(_amount) >= MAX_SUPPLY) { _amount = MAX_SUPPLY.sub(supply); maxSupplyHit = true; } if (_amount > 0) { _mint(_to, _amount); _moveDelegates(address(0), _delegates[_to], _amount); } } // Sets the addresses of the Tito farming contract, the Whirlpool staking contract, and the Uniswap SURF-ETH LP token function setContractAddresses(address _titoAddress, address payable _whirlpoolAddress, address _surfPoolAddress) public onlyOwner { if (_titoAddress != address(0)) titoAddress = _titoAddress; if (_whirlpoolAddress != address(0)) whirlpoolAddress = _whirlpoolAddress; if (_surfPoolAddress != address(0)) surfPoolAddress = _surfPoolAddress; } // Sets the SURF transfer fee that gets rewarded to Whirlpool stakers. Can't be higher than 10%. function setTransferFee(uint256 _transferFee) public onlyOwner { require(_transferFee <= 100, "over 10%"); transferFee = _transferFee; } // Add an address to the sender or recipient transfer whitelist function addToTransferWhitelist(bool _addToSenderWhitelist, address _address) public onlyOwner { if (_addToSenderWhitelist == true) senderWhitelist[_address] = true; else recipientWhitelist[_address] = true; } // Remove an address from the sender or recipient transfer whitelist function removeFromTransferWhitelist(bool _removeFromSenderWhitelist, address _address) public onlyOwner { if (_removeFromSenderWhitelist == true) senderWhitelist[_address] = false; else recipientWhitelist[_address] = false; } // Both the Tito and Whirlpool contracts will lock the SURF-ETH LP tokens they receive from their staking/unstaking fees here (ensuring liquidity forever). // This function allows SURF token holders to decide what to do with the locked LP tokens in the future function migrateLockedLPTokens(address _to, uint256 _amount) public onlyOwner { IERC20 surfPool = IERC20(surfPoolAddress); require(_amount > 0 && _amount <= surfPool.balanceOf(address(this)), "bad amount"); surfPool.transfer(_to, _amount); } function approveAndCall(address _spender, uint256 _tokens, bytes calldata _data) external returns (bool) { approve(_spender, _tokens); Callable(_spender).receiveApproval(msg.sender, _tokens, address(this), _data); return true; } function transferAndCall(address _to, uint256 _tokens, bytes calldata _data) external returns (bool) { uint256 _balanceBefore = balanceOf(_to); transfer(_to, _tokens); uint256 _tokensReceived = balanceOf(_to) - _balanceBefore; uint32 _size; assembly { _size := extcodesize(_to) } if (_size > 0) { require(Callable(_to).tokenCallback(msg.sender, _tokensReceived, _data)); } return true; } // There's a fee on every SURF transfer that gets sent to the Whirlpool staking contract which will start getting rewarded to stakers after the max supply is hit. // The transfer fee will reduce the front-running of Uniswap trades and will provide a major incentive to hold and stake SURF long-term. // Transfers to/from the Tito or Whirlpool contracts will not pay a fee. function _transfer(address sender, address recipient, uint256 amount) internal override { require(sender != address(0), "ERC20: transfer from the zero address"); require(recipient != address(0), "ERC20: transfer to the zero address"); uint256 transferFeeAmount; uint256 tokensToTransfer; if (amount > 0) { // Send a fee to the Whirlpool staking contract if this isn't a whitelisted transfer if (_isWhitelistedTransfer(sender, recipient) != true) { transferFeeAmount = amount.mul(transferFee).div(1000); _balances[whirlpoolAddress] = _balances[whirlpoolAddress].add(transferFeeAmount); _moveDelegates(_delegates[sender], _delegates[whirlpoolAddress], transferFeeAmount); Whirlpool(whirlpoolAddress).addSurfReward(sender, transferFeeAmount); emit Transfer(sender, whirlpoolAddress, transferFeeAmount); } tokensToTransfer = amount.sub(transferFeeAmount); _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); if (tokensToTransfer > 0) { _balances[recipient] = _balances[recipient].add(tokensToTransfer); _moveDelegates(_delegates[sender], _delegates[recipient], tokensToTransfer); // If the Whirlpool staking contract is the transfer recipient, addSurfReward gets called to keep things in sync if (recipient == whirlpoolAddress) Whirlpool(whirlpoolAddress).addSurfReward(sender, tokensToTransfer); } } emit Transfer(sender, recipient, tokensToTransfer); } // Internal function to determine if a SURF transfer is being sent or received by a whitelisted address function _isWhitelistedTransfer(address _sender, address _recipient) internal view returns (bool) { // The Whirlpool and Tito contracts are always whitelisted return _sender == whirlpoolAddress || _recipient == whirlpoolAddress || _sender == titoAddress || _recipient == titoAddress || senderWhitelist[_sender] == true || recipientWhitelist[_recipient] == true; } // Copied and modified from YAM code: // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernanceStorage.sol // https://github.com/yam-finance/yam-protocol/blob/master/contracts/token/YAMGovernance.sol // Which is copied and modified from COMPOUND: // https://github.com/compound-finance/compound-protocol/blob/master/contracts/Governance/Comp.sol /// @dev A record of each accounts delegate mapping (address => address) internal _delegates; /// @dev A checkpoint for marking number of votes from a given block struct Checkpoint { uint32 fromBlock; uint256 votes; } /// @dev A record of votes checkpoints for each account, by index mapping (address => mapping (uint32 => Checkpoint)) public checkpoints; /// @dev The number of checkpoints for each account mapping (address => uint32) public numCheckpoints; /// @dev The EIP-712 typehash for the contract's domain bytes32 public constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"); /// @dev The EIP-712 typehash for the delegation struct used by the contract bytes32 public constant DELEGATION_TYPEHASH = keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)"); /// @dev A record of states for signing / validating signatures mapping (address => uint) public nonces; /// @dev An event thats emitted when an account changes its delegate event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate); /// @dev An event thats emitted when a delegate account's vote balance changes event DelegateVotesChanged(address indexed delegate, uint previousBalance, uint newBalance); /** * @dev Delegate votes from `msg.sender` to `delegatee` * @param delegator The address to get delegatee for */ function delegates(address delegator) external view returns (address) { return _delegates[delegator]; } /** * @dev Delegate votes from `msg.sender` to `delegatee` * @param delegatee The address to delegate votes to */ function delegate(address delegatee) external { return _delegate(msg.sender, delegatee); } /** * @dev Delegates votes from signatory to `delegatee` * @param delegatee The address to delegate votes to * @param nonce The contract state required to match the signature * @param expiry The time at which to expire the signature * @param v The recovery byte of the signature * @param r Half of the ECDSA signature pair * @param s Half of the ECDSA signature pair */ function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) external { bytes32 domainSeparator = keccak256( abi.encode( DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this) ) ); bytes32 structHash = keccak256( abi.encode( DELEGATION_TYPEHASH, delegatee, nonce, expiry ) ); bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, structHash ) ); address signatory = ecrecover(digest, v, r, s); require(signatory != address(0), "SURF::delegateBySig: invalid signature"); require(nonce == nonces[signatory]++, "SURF::delegateBySig: invalid nonce"); require(now <= expiry, "SURF::delegateBySig: signature expired"); return _delegate(signatory, delegatee); } /** * @dev Gets the current votes balance for `account` * @param account The address to get votes balance * @return The number of current votes for `account` */ function getCurrentVotes(address account) external view returns (uint256) { uint32 nCheckpoints = numCheckpoints[account]; return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0; } /** * @dev Determine the prior number of votes for an account as of a block number * @dev Block number must be a finalized block or else this function will revert to prevent misinformation. * @param account The address of the account to check * @param blockNumber The block number to get the vote balance at * @return The number of votes the account had as of the given block */ function getPriorVotes(address account, uint blockNumber) external view returns (uint256) { require(blockNumber < block.number, "SURF::getPriorVotes: not yet determined"); uint32 nCheckpoints = numCheckpoints[account]; if (nCheckpoints == 0) { return 0; } // First check most recent balance if (checkpoints[account][nCheckpoints - 1].fromBlock <= blockNumber) { return checkpoints[account][nCheckpoints - 1].votes; } // Next check implicit zero balance if (checkpoints[account][0].fromBlock > blockNumber) { return 0; } uint32 lower = 0; uint32 upper = nCheckpoints - 1; while (upper > lower) { uint32 center = upper - (upper - lower) / 2; // ceil, avoiding overflow Checkpoint memory cp = checkpoints[account][center]; if (cp.fromBlock == blockNumber) { return cp.votes; } else if (cp.fromBlock < blockNumber) { lower = center; } else { upper = center - 1; } } return checkpoints[account][lower].votes; } function _delegate(address delegator, address delegatee) internal { address currentDelegate = _delegates[delegator]; uint256 delegatorBalance = balanceOf(delegator); // balance of underlying SURFs (not scaled); _delegates[delegator] = delegatee; emit DelegateChanged(delegator, currentDelegate, delegatee); _moveDelegates(currentDelegate, delegatee, delegatorBalance); } function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal { if (srcRep != dstRep && amount > 0) { if (srcRep != address(0)) { // decrease old representative uint32 srcRepNum = numCheckpoints[srcRep]; uint256 srcRepOld = srcRepNum > 0 ? checkpoints[srcRep][srcRepNum - 1].votes : 0; uint256 srcRepNew = srcRepOld.sub(amount); _writeCheckpoint(srcRep, srcRepNum, srcRepOld, srcRepNew); } if (dstRep != address(0)) { // increase new representative uint32 dstRepNum = numCheckpoints[dstRep]; uint256 dstRepOld = dstRepNum > 0 ? checkpoints[dstRep][dstRepNum - 1].votes : 0; uint256 dstRepNew = dstRepOld.add(amount); _writeCheckpoint(dstRep, dstRepNum, dstRepOld, dstRepNew); } } } function _writeCheckpoint(address delegatee, uint32 nCheckpoints, uint256 oldVotes, uint256 newVotes) internal { uint32 blockNumber = safe32(block.number, "SURF::_writeCheckpoint: block number exceeds 32 bits"); if (nCheckpoints > 0 && checkpoints[delegatee][nCheckpoints - 1].fromBlock == blockNumber) { checkpoints[delegatee][nCheckpoints - 1].votes = newVotes; } else { checkpoints[delegatee][nCheckpoints] = Checkpoint(blockNumber, newVotes); numCheckpoints[delegatee] = nCheckpoints + 1; } emit DelegateVotesChanged(delegatee, oldVotes, newVotes); } function safe32(uint n, string memory errorMessage) internal pure returns (uint32) { require(n < 2**32, errorMessage); return uint32(n); } function getChainId() internal pure returns (uint) { uint256 chainId; assembly { chainId := chainid() } return chainId; } }
/* _____ __ ______ ______ ___________ _____ _ ______________ / ___// / / / __ \/ ____/ / ____/ _/ | / / | / | / / ____/ ____/ \__ \/ / / / /_/ / /_ / /_ / // |/ / /| | / |/ / / / __/ ___/ / /_/ / _, _/ __/ _ / __/ _/ // /| / ___ |/ /| / /___/ /___ /____/\____/_/ |_/_/ (_) /_/ /___/_/ |_/_/ |_/_/ |_/\____/_____/ Website: https://surf.finance Created by Proof and sol_dev, with help from Zoma and Mr Fahrenheit Audited by Aegis DAO and Sherlock Security */ pragma solidity ^0.6.12; import './Ownable.sol'; import './SafeMath.sol'; import './SafeERC20.sol'; import './IERC20.sol'; import './IUniswapV2Router02.sol'; import './UniStakingInterfaces.sol'; import './SURF.sol'; import './Whirlpool.sol'; // Tito is the master of SURF. He can make SURF, is a fair guy, and a great instructor. contract Tito is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user. struct UserInfo { uint256 staked; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. uint256 uniRewardDebt; // UNI staking reward debt. See explanation below. uint256 claimed; // Tracks the amount of SURF claimed by the user. uint256 uniClaimed; // Tracks the amount of UNI claimed by the user. } // Info of each pool. struct PoolInfo { IERC20 token; // Address of token contract. IERC20 lpToken; // Address of LP token contract. uint256 apr; // Fixed APR for the pool. Determines how many SURFs to distribute per block. uint256 lastSurfRewardBlock; // Last block number that SURF rewards were distributed. uint256 accSurfPerShare; // Accumulated SURFs per share, times 1e12. See below. uint256 accUniPerShare; // Accumulated UNIs per share, times 1e12. See below. address uniStakeContract; // Address of UNI staking contract (if applicable). } // We do some fancy math here. Basically, any point in time, the amount of SURFs // entitled to a user but is pending to be distributed is: // // pending reward = (user.staked * pool.accSurfPerShare) - user.rewardDebt // // Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens: // 1. The pool's `accSurfPerShare` (and `lastSurfRewardBlock`) gets updated. // 2. User receives the pending reward sent to his/her address. // 3. User's `staked` amount gets updated. // 4. User's `rewardDebt` gets updated. // The SURF TOKEN! SURF public surf; // The address of the SURF-ETH Uniswap pool address public surfPoolAddress; // The Whirlpool staking contract Whirlpool public whirlpool; // The Uniswap v2 Router IUniswapV2Router02 internal uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // The UNI Staking Rewards Factory StakingRewardsFactory internal uniStakingFactory = StakingRewardsFactory(0x3032Ab3Fa8C01d786D29dAdE018d7f2017918e12); // The UNI Token IERC20 internal uniToken = IERC20(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984); // The WETH Token IERC20 internal weth; // Dev address address payable public devAddress; // Info of each pool. PoolInfo[] public poolInfo; mapping(address => bool) public existingPools; // Info of each user that stakes LP tokens. mapping (uint256 => mapping (address => UserInfo)) public userInfo; // Mapping of whitelisted contracts so that certain contracts like the Aegis pool can interact with the Tito contract mapping(address => bool) public contractWhitelist; // The block number when SURF mining starts. uint256 public startBlock; // Becomes true once the SURF-ETH Uniswap is created (no sooner than 500 blocks after launch) bool public surfPoolActive = false; // The staking fees collected during the first 500 blocks will seed the SURF-ETH Uniswap pool uint256 public initialSurfPoolETH = 0; // 5% of every deposit into any secondary pool (not SURF-ETH) will be converted to SURF (on Uniswap) and sent to the Whirlpool staking contract which becomes active and starts distributing the accumulated SURF to stakers once the max supply is hit uint256 public surfSentToWhirlpool = 0; // The amount of ETH donated to the SURF community by partner projects uint256 public donatedETH = 0; // Certain partner projects need to donate 25 ETH to the SURF community to get a beach uint256 internal constant minimumDonationAmount = 25 * 10**18; // Mapping of addresses that donated ETH on behalf of a partner project mapping(address => address) internal donaters; // Mapping of the size of donations from partner projects mapping(address => uint256) internal donations; // Approximate number of blocks per year - assumes 13 second blocks uint256 internal constant APPROX_BLOCKS_PER_YEAR = uint256(uint256(365 days) / uint256(13 seconds)); // The default APR for each pool will be 1,000% uint256 internal constant DEFAULT_APR = 1000; // There will be a 1000 block Soft Launch in which SURF is minted to each pool at a static rate to make the start as fair as possible uint256 internal constant SOFT_LAUNCH_DURATION = 1000; // During the Soft Launch, all pools except for the SURF-ETH pool will mint 40 SURF per block. Once it's activated, the SURF-ETH pool will mint the same amount of SURF per block as all of the other pools combined until the end of the Soft Launch uint256 internal constant SOFT_LAUNCH_SURF_PER_BLOCK = 40 * 10**18; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Claim(address indexed user, uint256 indexed pid, uint256 surfAmount, uint256 uniAmount); event ClaimAll(address indexed user, uint256 surfAmount, uint256 uniAmount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); event SurfBuyback(address indexed user, uint256 ethSpentOnSurf, uint256 surfBought); event SurfPoolActive(address indexed user, uint256 surfLiquidity, uint256 ethLiquidity); constructor( SURF _surf, address payable _devAddress, uint256 _startBlock ) public { surf = _surf; devAddress = _devAddress; startBlock = _startBlock; weth = IERC20(uniswapRouter.WETH()); // Calculate the address the SURF-ETH Uniswap pool will exist at address uniswapfactoryAddress = uniswapRouter.factory(); address surfAddress = address(surf); address wethAddress = address(weth); // token0 must be strictly less than token1 by sort order to determine the correct address (address token0, address token1) = surfAddress < wethAddress ? (surfAddress, wethAddress) : (wethAddress, surfAddress); surfPoolAddress = address(uint(keccak256(abi.encodePacked( hex'ff', uniswapfactoryAddress, keccak256(abi.encodePacked(token0, token1)), hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' )))); _addInitialPools(); } receive() external payable {} // Internal function to add a new LP Token pool function _addPool(address _token, address _lpToken) internal { uint256 apr = DEFAULT_APR; if (_token == address(surf)) apr = apr * 5; uint256 lastSurfRewardBlock = block.number > startBlock ? block.number : startBlock; poolInfo.push( PoolInfo({ token: IERC20(_token), lpToken: IERC20(_lpToken), apr: apr, lastSurfRewardBlock: lastSurfRewardBlock, accSurfPerShare: 0, accUniPerShare: 0, uniStakeContract: address(0) }) ); existingPools[_lpToken] = true; } // Internal function that adds all of the pools that will be available at launch. Called by the constructor function _addInitialPools() internal { _addPool(address(surf), surfPoolAddress); // SURF-ETH _addPool(0xdAC17F958D2ee523a2206206994597C13D831ec7, 0x0d4a11d5EEaaC28EC3F61d100daF4d40471f1852); // ETH-USDT _addPool(0x6B175474E89094C44Da98b954EedeAC495271d0F, 0xA478c2975Ab1Ea89e8196811F51A7B7Ade33eB11); // DAI-ETH _addPool(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, 0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc); // USDC-ETH _addPool(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599, 0xBb2b8038a1640196FbE3e38816F3e67Cba72D940); // WBTC-ETH _addPool(0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984, 0xd3d2E2692501A5c9Ca623199D38826e513033a17); // UNI-ETH _addPool(0x514910771AF9Ca656af840dff83E8264EcF986CA, 0xa2107FA5B38d9bbd2C461D6EDf11B11A50F6b974); // LINK-ETH _addPool(0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9, 0xDFC14d2Af169B0D36C4EFF567Ada9b2E0CAE044f); // AAVE-ETH _addPool(0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F, 0x43AE24960e5534731Fc831386c07755A2dc33D47); // SNX-ETH _addPool(0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2, 0xC2aDdA861F89bBB333c90c492cB837741916A225); // MKR-ETH _addPool(0xc00e94Cb662C3520282E6f5717214004A7f26888, 0xCFfDdeD873554F362Ac02f8Fb1f02E5ada10516f); // COMP-ETH _addPool(0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e, 0x2fDbAdf3C4D5A8666Bc06645B8358ab803996E28); // YFI-ETH _addPool(0xba100000625a3754423978a60c9317c58a424e3D, 0xA70d458A4d9Bc0e6571565faee18a48dA5c0D593); // BAL-ETH _addPool(0x1494CA1F11D487c2bBe4543E90080AeBa4BA3C2b, 0x4d5ef58aAc27d99935E5b6B4A6778ff292059991); // DPI-ETH _addPool(0xD46bA6D942050d489DBd938a2C909A5d5039A161, 0xc5be99A02C6857f9Eac67BbCE58DF5572498F40c); // AMPL-ETH _addPool(0x2b591e99afE9f32eAA6214f7B7629768c40Eeb39, 0x55D5c232D921B9eAA6b37b5845E439aCD04b4DBa); // HEX-ETH _addPool(0x93ED3FBe21207Ec2E8f2d3c3de6e058Cb73Bc04d, 0x343FD171caf4F0287aE6b87D75A8964Dc44516Ab); // PNK-ETH _addPool(0x429881672B9AE42b8EbA0E26cD9C73711b891Ca5, 0xdc98556Ce24f007A5eF6dC1CE96322d65832A819); // PICKLE-ETH _addPool(0x84294FC9710e1252d407d3D80A84bC39001bd4A8, 0x0C5136B5d184379fa15bcA330784f2d5c226Fe96); // NUTS-ETH _addPool(0x821144518dfE9e7b44fCF4d0824e15e8390d4637, 0x490B5B2489eeFC4106C69743F657e3c4A2870aC5); // ATIS-ETH _addPool(0xB9464ef80880c5aeA54C7324c0b8Dd6ca6d05A90, 0xa8D0f6769AB020877f262D8Cd747c188D9097d7E); // LOCK-ETH _addPool(0x926dbD499d701C61eABe2d576e770ECCF9c7F4F3, 0xC7c0EDf0b5f89eff96aF0E31643Bd588ad63Ea23); // aDAO-ETH _addPool(0x3A9FfF453d50D4Ac52A6890647b823379ba36B9E, 0x260E069deAd76baAC587B5141bB606Ef8b9Bab6c); // SHUF-ETH _addPool(0x9720Bcf5a92542D4e286792fc978B63a09731CF0, 0x08538213596fB2c392e9c5d4935ad37645600a57); // OTBC-ETH _addPool(0xEEF9f339514298C6A857EfCfC1A762aF84438dEE, 0x23d15EDceb5B5B3A23347Fa425846DE80a2E8e5C); // HEZ-ETH // These beaches will be manually added after their teams make the 25 ETH donation // _addPool(0x6F87D756DAf0503d08Eb8993686c7Fc01Dc44fB1, 0xd2E0C4928789e5DB620e53af29F5fC7bcA262635); // TRADE-ETH } // Get the pending SURFs for a user from 1 pool function _pendingSurf(uint256 _pid, address _user) internal view returns (uint256) { if (_pid == 0 && surfPoolActive != true) return 0; PoolInfo memory pool = poolInfo[_pid]; UserInfo memory user = userInfo[_pid][_user]; uint256 accSurfPerShare = pool.accSurfPerShare; uint256 lpSupply = _getPoolSupply(_pid); if (block.number > pool.lastSurfRewardBlock && lpSupply != 0) { uint256 surfReward = _calculateSurfReward(_pid, lpSupply); // Make sure that surfReward won't push the total supply of SURF past surf.MAX_SUPPLY() uint256 surfTotalSupply = surf.totalSupply(); if (surfTotalSupply.add(surfReward) >= surf.MAX_SUPPLY()) { surfReward = surf.MAX_SUPPLY().sub(surfTotalSupply); } accSurfPerShare = accSurfPerShare.add(surfReward.mul(1e12).div(lpSupply)); } return user.staked.mul(accSurfPerShare).div(1e12).sub(user.rewardDebt); } // Get the pending UNIs for a user from 1 pool function _pendingUni(uint256 _pid, address _user) internal view returns (uint256) { PoolInfo memory pool = poolInfo[_pid]; UserInfo memory user = userInfo[_pid][_user]; uint256 accUniPerShare = pool.accUniPerShare; uint256 lpSupply = _getPoolSupply(_pid); if (pool.uniStakeContract != address(0) && lpSupply != 0) { uint256 uniReward = IStakingRewards(pool.uniStakeContract).earned(address(this)); accUniPerShare = accUniPerShare.add(uniReward.mul(1e12).div(lpSupply)); } return user.staked.mul(accUniPerShare).div(1e12).sub(user.uniRewardDebt); } // Calculate the current surfReward for a specific pool function _calculateSurfReward(uint256 _pid, uint256 _lpSupply) internal view returns (uint256 surfReward) { if (surf.maxSupplyHit() != true) { PoolInfo memory pool = poolInfo[_pid]; uint256 multiplier = block.number - pool.lastSurfRewardBlock; // There will be a 1000 block Soft Launch where SURF is minted at a static rate to make things as fair as possible if (block.number < startBlock + SOFT_LAUNCH_DURATION) { // The SURF-ETH pool isn't active until the Uniswap pool is created, which can't happen until at least 500 blocks have passed. Once active, it mints 1000 SURF per block (the same amount of SURF per block as all of the other pools combined) until the Soft Launch ends if (_pid != 0) { // For the first 1000 blocks, give 40 SURF per block to all other pools that have staked LP tokens surfReward = multiplier * SOFT_LAUNCH_SURF_PER_BLOCK; } else if (surfPoolActive == true) { surfReward = multiplier * 25 * SOFT_LAUNCH_SURF_PER_BLOCK; } } else if (_pid != 0 && surfPoolActive != true) { // Keep minting 40 tokens per block since the Soft Launch is over but the SURF-ETH pool still isn't active (would only be due to no one calling the activateSurfPool function) surfReward = multiplier * SOFT_LAUNCH_SURF_PER_BLOCK; } else if (surfPoolActive == true) { // Afterwards, give surfReward based on the pool's fixed APR. // Fast low gas cost way of calculating prices since this can be called every block. uint256 surfPrice = _getSurfPrice(); uint256 lpTokenPrice = 10**18 * 2 * weth.balanceOf(address(pool.lpToken)) / pool.lpToken.totalSupply(); uint256 scaledTotalLiquidityValue = _lpSupply * lpTokenPrice; surfReward = multiplier * ((pool.apr * scaledTotalLiquidityValue / surfPrice) / APPROX_BLOCKS_PER_YEAR) / 100; } } } function poolLength() external view returns (uint256) { return poolInfo.length; } // Internal view function to get all of the stored data for a single pool function _getPoolData(uint256 _pid) internal view returns (address, address, bool, uint256, uint256, uint256, uint256) { PoolInfo memory pool = poolInfo[_pid]; return (address(pool.token), address(pool.lpToken), pool.uniStakeContract != address(0), pool.apr, pool.lastSurfRewardBlock, pool.accSurfPerShare, pool.accUniPerShare); } // View function to see all of the stored data for every pool on the frontend function _getAllPoolData() internal view returns (address[] memory, address[] memory, bool[] memory, uint[] memory, uint[] memory, uint[2][] memory) { uint256 length = poolInfo.length; address[] memory tokenData = new address[](length); address[] memory lpTokenData = new address[](length); bool[] memory isUniData = new bool[](length); uint[] memory aprData = new uint[](length); uint[] memory lastSurfRewardBlockData = new uint[](length); uint[2][] memory accTokensPerShareData = new uint[2][](length); for (uint256 pid = 0; pid < length; ++pid) { (tokenData[pid], lpTokenData[pid], isUniData[pid], aprData[pid], lastSurfRewardBlockData[pid], accTokensPerShareData[pid][0], accTokensPerShareData[pid][1]) = _getPoolData(pid); } return (tokenData, lpTokenData, isUniData, aprData, lastSurfRewardBlockData, accTokensPerShareData); } // Internal view function to get all of the extra data for a single pool function _getPoolMetadataFor(uint256 _pid, address _user, uint256 _surfPrice) internal view returns (uint[17] memory poolMetadata) { PoolInfo memory pool = poolInfo[_pid]; uint256 totalSupply; uint256 totalLPSupply; uint256 stakedLPSupply; uint256 tokenPrice; uint256 lpTokenPrice; uint256 totalLiquidityValue; uint256 surfPerBlock; if (_pid != 0 || surfPoolActive == true) { totalSupply = pool.token.totalSupply(); totalLPSupply = pool.lpToken.totalSupply(); stakedLPSupply = _getPoolSupply(_pid); tokenPrice = 10**uint256(pool.token.decimals()) * weth.balanceOf(address(pool.lpToken)) / pool.token.balanceOf(address(pool.lpToken)); lpTokenPrice = 10**18 * 2 * weth.balanceOf(address(pool.lpToken)) / totalLPSupply; totalLiquidityValue = stakedLPSupply * lpTokenPrice / 1e18; } // Only calculate with fixed apr after the Soft Launch if (block.number >= startBlock + SOFT_LAUNCH_DURATION) { surfPerBlock = ((pool.apr * 1e18 * totalLiquidityValue / _surfPrice) / APPROX_BLOCKS_PER_YEAR) / 100; } else { if (_pid != 0) { surfPerBlock = SOFT_LAUNCH_SURF_PER_BLOCK; } else if (surfPoolActive == true) { surfPerBlock = 25 * SOFT_LAUNCH_SURF_PER_BLOCK; } } // Global pool information poolMetadata[0] = totalSupply; poolMetadata[1] = totalLPSupply; poolMetadata[2] = stakedLPSupply; poolMetadata[3] = tokenPrice; poolMetadata[4] = lpTokenPrice; poolMetadata[5] = totalLiquidityValue; poolMetadata[6] = surfPerBlock; poolMetadata[7] = pool.token.decimals(); // User pool information if (_pid != 0 || surfPoolActive == true) { UserInfo memory _userInfo = userInfo[_pid][_user]; poolMetadata[8] = pool.token.balanceOf(_user); poolMetadata[9] = pool.token.allowance(_user, address(this)); poolMetadata[10] = pool.lpToken.balanceOf(_user); poolMetadata[11] = pool.lpToken.allowance(_user, address(this)); poolMetadata[12] = _userInfo.staked; poolMetadata[13] = _pendingSurf(_pid, _user); poolMetadata[14] = _pendingUni(_pid, _user); poolMetadata[15] = _userInfo.claimed; poolMetadata[16] = _userInfo.uniClaimed; } } // View function to see all of the extra pool data (token prices, total staked supply, total liquidity value, etc) on the frontend function _getAllPoolMetadataFor(address _user) internal view returns (uint[17][] memory allMetadata) { uint256 length = poolInfo.length; // Extra data for the frontend allMetadata = new uint[17][](length); // We'll need the current SURF price to make our calculations uint256 surfPrice = _getSurfPrice(); for (uint256 pid = 0; pid < length; ++pid) { allMetadata[pid] = _getPoolMetadataFor(pid, _user, surfPrice); } } // View function to see all of the data for all pools on the frontend function getAllPoolInfoFor(address _user) external view returns (address[] memory tokens, address[] memory lpTokens, bool[] memory isUnis, uint[] memory aprs, uint[] memory lastSurfRewardBlocks, uint[2][] memory accTokensPerShares, uint[17][] memory metadatas) { (tokens, lpTokens, isUnis, aprs, lastSurfRewardBlocks, accTokensPerShares) = _getAllPoolData(); metadatas = _getAllPoolMetadataFor(_user); } // Internal view function to get the current price of SURF on Uniswap function _getSurfPrice() internal view returns (uint256 surfPrice) { uint256 surfBalance = surf.balanceOf(surfPoolAddress); if (surfBalance > 0) { surfPrice = 10**18 * weth.balanceOf(surfPoolAddress) / surfBalance; } } // View function to show all relevant platform info on the frontend function getAllInfoFor(address _user) external view returns (bool poolActive, uint256[8] memory info) { poolActive = surfPoolActive; info[0] = blocksUntilLaunch(); info[1] = blocksUntilSurfPoolCanBeActivated(); info[2] = blocksUntilSoftLaunchEnds(); info[3] = surf.totalSupply(); info[4] = _getSurfPrice(); if (surfPoolActive) { info[5] = IERC20(surfPoolAddress).balanceOf(address(surf)); } info[6] = surfSentToWhirlpool; info[7] = surf.balanceOf(_user); } // View function to see the number of blocks remaining until launch on the frontend function blocksUntilLaunch() public view returns (uint256) { if (block.number >= startBlock) return 0; else return startBlock.sub(block.number); } // View function to see the number of blocks remaining until the SURF pool can be activated on the frontend function blocksUntilSurfPoolCanBeActivated() public view returns (uint256) { uint256 surfPoolActivationBlock = startBlock + SOFT_LAUNCH_DURATION.div(2); if (block.number >= surfPoolActivationBlock) return 0; else return surfPoolActivationBlock.sub(block.number); } // View function to see the number of blocks remaining until the Soft Launch ends on the frontend function blocksUntilSoftLaunchEnds() public view returns (uint256) { uint256 softLaunchEndBlock = startBlock + SOFT_LAUNCH_DURATION; if (block.number >= softLaunchEndBlock) return 0; else return softLaunchEndBlock.sub(block.number); } // Update reward variables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = (surfPoolActive == true ? 0 : 1); pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { require(msg.sender == tx.origin || msg.sender == owner() || contractWhitelist[msg.sender] == true, "no contracts"); // Prevent flash loan attacks that manipulate prices. PoolInfo storage pool = poolInfo[_pid]; uint256 lpSupply = _getPoolSupply(_pid); // Handle the UNI staking rewards contract for the LP token if one exists. // The SURF-ETH pool would break by using the UNI staking rewards contract if one is made for it so it will be ignored if (_pid != 0) { // Check to see if the LP token has a UNI staking rewards contract to forward deposits to so that users can earn both SURF and UNI if (pool.uniStakeContract == address(0)) { (address uniStakeContract,) = uniStakingFactory.stakingRewardsInfoByStakingToken(address(pool.lpToken)); // If a UNI staking rewards contract exists then transfer all of the LP tokens to it to start earning UNI if (uniStakeContract != address(0)) { pool.uniStakeContract = uniStakeContract; if (lpSupply > 0) { pool.lpToken.safeApprove(uniStakeContract, 0); pool.lpToken.safeApprove(uniStakeContract, lpSupply); IStakingRewards(pool.uniStakeContract).stake(lpSupply); } } } // A UNI staking rewards contract for this LP token is being used so get any pending UNI rewards if (pool.uniStakeContract != address(0)) { uint256 pendingUniTokens = IStakingRewards(pool.uniStakeContract).earned(address(this)); if (pendingUniTokens > 0) { uint256 uniBalanceBefore = uniToken.balanceOf(address(this)); IStakingRewards(pool.uniStakeContract).getReward(); uint256 uniBalanceAfter = uniToken.balanceOf(address(this)); pendingUniTokens = uniBalanceAfter.sub(uniBalanceBefore); pool.accUniPerShare = pool.accUniPerShare.add(pendingUniTokens.mul(1e12).div(lpSupply)); } } } // Only update the pool if the max SURF supply hasn't been hit if (surf.maxSupplyHit() != true) { if ((block.number <= pool.lastSurfRewardBlock) || (_pid == 0 && surfPoolActive != true)) { return; } if (lpSupply == 0) { pool.lastSurfRewardBlock = block.number; return; } uint256 surfReward = _calculateSurfReward(_pid, lpSupply); // Make sure that surfReward won't push the total supply of SURF past surf.MAX_SUPPLY() uint256 surfTotalSupply = surf.totalSupply(); if (surfTotalSupply.add(surfReward) >= surf.MAX_SUPPLY()) { surfReward = surf.MAX_SUPPLY().sub(surfTotalSupply); } // surf.mint(devAddress, surfReward.div(10)); Not minting 10% to the devs like Sushi, Sashimi, and Takeout do if (surfReward > 0) { surf.mint(address(this), surfReward); pool.accSurfPerShare = pool.accSurfPerShare.add(surfReward.mul(1e12).div(lpSupply)); pool.lastSurfRewardBlock = block.number; } if (surf.maxSupplyHit() == true) { whirlpool.activate(); } } } // Internal view function to get the amount of LP tokens staked in the specified pool function _getPoolSupply(uint256 _pid) internal view returns (uint256 lpSupply) { PoolInfo memory pool = poolInfo[_pid]; if (pool.uniStakeContract != address(0)) { lpSupply = IStakingRewards(pool.uniStakeContract).balanceOf(address(this)); } else { lpSupply = pool.lpToken.balanceOf(address(this)); } } // Deposits LP tokens in the specified pool to start earning the user SURF function deposit(uint256 _pid, uint256 _amount) external { depositFor(_pid, msg.sender, _amount); } // Deposits LP tokens in the specified pool on behalf of another user function depositFor(uint256 _pid, address _user, uint256 _amount) public { require(msg.sender == tx.origin || contractWhitelist[msg.sender] == true, "no contracts"); require(surf.maxSupplyHit() != true, "pools closed"); require(_pid != 0 || surfPoolActive == true, "surf pool not active"); require(_amount > 0, "deposit something"); updatePool(_pid); PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; // The sender needs to give approval to the Tito contract for the specified amount of the LP token first pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amount); // Claim any pending SURF and UNI _claimRewardsFromPool(_pid, _user); // Each pool has a 10% staking fee. If staking in the SURF-ETH pool, 100% of the fee gets permanently locked in the SURF contract (gives SURF liquidity forever). // If staking in any other pool, 50% of the fee is used to buyback SURF which is sent to the Whirlpool staking contract where it will start getting distributed to stakers after the max supply is hit, and 50% goes to the team. // The team is never minted or rewarded SURF for any reason to keep things as fair as possible. uint256 stakingFeeAmount = _amount.div(10); uint256 remainingUserAmount = _amount.sub(stakingFeeAmount); // If a UNI staking rewards contract is available, use it if (pool.uniStakeContract != address(0)) { pool.lpToken.safeApprove(pool.uniStakeContract, 0); pool.lpToken.safeApprove(pool.uniStakeContract, remainingUserAmount); IStakingRewards(pool.uniStakeContract).stake(remainingUserAmount); } // The user is depositing to the SURF-ETH pool so permanently lock all of the LP tokens from the staking fee in the SURF contract if (_pid == 0) { pool.lpToken.transfer(address(surf), stakingFeeAmount); } else { uint256 ethBalanceBeforeSwap = address(this).balance; // Remove the liquidity from the pool uint256 deadline = block.timestamp + 5 minutes; pool.lpToken.safeApprove(address(uniswapRouter), 0); pool.lpToken.safeApprove(address(uniswapRouter), stakingFeeAmount); uniswapRouter.removeLiquidityETHSupportingFeeOnTransferTokens(address(pool.token), stakingFeeAmount, 0, 0, address(this), deadline); // Swap the ERC-20 token for ETH uint256 tokensToSwap = pool.token.balanceOf(address(this)); require(tokensToSwap > 0, "bad token swap"); address[] memory poolPath = new address[](2); poolPath[0] = address(pool.token); poolPath[1] = address(weth); pool.token.safeApprove(address(uniswapRouter), 0); pool.token.safeApprove(address(uniswapRouter), tokensToSwap); uniswapRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(tokensToSwap, 0, poolPath, address(this), deadline); uint256 ethBalanceAfterSwap = address(this).balance; uint256 ethReceivedFromStakingFee; uint256 teamFeeAmount; // If surfPoolActive == true then perform a buyback of SURF using all of the ETH in the contract and then send it to the Whirlpool staking contract. Otherwise, the ETH will be used to seed the initial liquidity in the SURF-ETH Uniswap pool when activateSurfPool is called if (surfPoolActive == true) { require(ethBalanceAfterSwap > 0, "bad eth swap"); teamFeeAmount = ethBalanceAfterSwap.div(2); ethReceivedFromStakingFee = ethBalanceAfterSwap.sub(teamFeeAmount); // The SURF-ETH pool is active, so let's use the ETH to buyback SURF and send it to the Whirlpool staking contract uint256 surfBought = _buySurf(ethReceivedFromStakingFee); // Send the SURF rewards to the Whirlpool staking contract surfSentToWhirlpool += surfBought; _safeSurfTransfer(address(whirlpool), surfBought); } else { ethReceivedFromStakingFee = ethBalanceAfterSwap.sub(ethBalanceBeforeSwap); require(ethReceivedFromStakingFee > 0, "bad eth swap"); teamFeeAmount = ethReceivedFromStakingFee.div(2); } if (teamFeeAmount > 0) devAddress.transfer(teamFeeAmount); } // Add the remaining amount to the user's staked balance uint256 _currentRewardDebt = 0; uint256 _currentUniRewardDebt = 0; if (surfPoolActive != true) { _currentRewardDebt = user.staked.mul(pool.accSurfPerShare).div(1e12).sub(user.rewardDebt); _currentUniRewardDebt = user.staked.mul(pool.accUniPerShare).div(1e12).sub(user.uniRewardDebt); } user.staked = user.staked.add(remainingUserAmount); user.rewardDebt = user.staked.mul(pool.accSurfPerShare).div(1e12).sub(_currentRewardDebt); user.uniRewardDebt = user.staked.mul(pool.accUniPerShare).div(1e12).sub(_currentUniRewardDebt); emit Deposit(_user, _pid, _amount); } // Internal function that buys back SURF with the amount of ETH specified function _buySurf(uint256 _amount) internal returns (uint256 surfBought) { uint256 ethBalance = address(this).balance; if (_amount > ethBalance) _amount = ethBalance; if (_amount > 0) { uint256 deadline = block.timestamp + 5 minutes; address[] memory surfPath = new address[](2); surfPath[0] = address(weth); surfPath[1] = address(surf); uint256[] memory amounts = uniswapRouter.swapExactETHForTokens{value: _amount}(0, surfPath, address(this), deadline); surfBought = amounts[1]; } if (surfBought > 0) emit SurfBuyback(msg.sender, _amount, surfBought); } // Internal function to claim earned SURF and UNI from Tito. Claiming won't work until surfPoolActive == true function _claimRewardsFromPool(uint256 _pid, address _user) internal { PoolInfo memory pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; if (surfPoolActive != true || user.staked == 0) return; uint256 userUniPending = user.staked.mul(pool.accUniPerShare).div(1e12).sub(user.uniRewardDebt); uint256 uniBalance = uniToken.balanceOf(address(this)); if (userUniPending > uniBalance) userUniPending = uniBalance; if (userUniPending > 0) { user.uniClaimed += userUniPending; uniToken.transfer(_user, userUniPending); } uint256 userSurfPending = user.staked.mul(pool.accSurfPerShare).div(1e12).sub(user.rewardDebt); if (userSurfPending > 0) { user.claimed += userSurfPending; _safeSurfTransfer(_user, userSurfPending); } if (userSurfPending > 0 || userUniPending > 0) { emit Claim(_user, _pid, userSurfPending, userUniPending); } } // Claim all earned SURF and UNI from a single pool. Claiming won't work until surfPoolActive == true function claim(uint256 _pid) public { require(surfPoolActive == true, "surf pool not active"); updatePool(_pid); _claimRewardsFromPool(_pid, msg.sender); UserInfo storage user = userInfo[_pid][msg.sender]; PoolInfo memory pool = poolInfo[_pid]; user.rewardDebt = user.staked.mul(pool.accSurfPerShare).div(1e12); user.uniRewardDebt = user.staked.mul(pool.accUniPerShare).div(1e12); } // Claim all earned SURF and UNI from all pools. Claiming won't work until surfPoolActive == true function claimAll() public { require(surfPoolActive == true, "surf pool not active"); uint256 totalPendingSurfAmount = 0; uint256 totalPendingUniAmount = 0; uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { UserInfo storage user = userInfo[pid][msg.sender]; if (user.staked > 0) { updatePool(pid); PoolInfo storage pool = poolInfo[pid]; uint256 accSurfPerShare = pool.accSurfPerShare; uint256 accUniPerShare = pool.accUniPerShare; uint256 pendingPoolSurfRewards = user.staked.mul(accSurfPerShare).div(1e12).sub(user.rewardDebt); user.claimed += pendingPoolSurfRewards; totalPendingSurfAmount = totalPendingSurfAmount.add(pendingPoolSurfRewards); user.rewardDebt = user.staked.mul(accSurfPerShare).div(1e12); uint256 pendingPoolUniRewards = user.staked.mul(accUniPerShare).div(1e12).sub(user.uniRewardDebt); user.uniClaimed += pendingPoolUniRewards; totalPendingUniAmount = totalPendingUniAmount.add(pendingPoolUniRewards); user.uniRewardDebt = user.staked.mul(accUniPerShare).div(1e12); } } require(totalPendingSurfAmount > 0 || totalPendingUniAmount > 0, "nothing to claim"); uint256 uniBalance = uniToken.balanceOf(address(this)); if (totalPendingUniAmount > uniBalance) totalPendingUniAmount = uniBalance; if (totalPendingUniAmount > 0) uniToken.transfer(msg.sender, totalPendingUniAmount); if (totalPendingSurfAmount > 0) _safeSurfTransfer(msg.sender, totalPendingSurfAmount); emit ClaimAll(msg.sender, totalPendingSurfAmount, totalPendingUniAmount); } // Withdraw LP tokens and earned SURF from Tito. Withdrawing won't work until surfPoolActive == true function withdraw(uint256 _pid, uint256 _amount) public { require(surfPoolActive == true, "surf pool not active"); UserInfo storage user = userInfo[_pid][msg.sender]; require(_amount > 0 && user.staked >= _amount, "withdraw: not good"); updatePool(_pid); // Claim any pending SURF and UNI _claimRewardsFromPool(_pid, msg.sender); PoolInfo memory pool = poolInfo[_pid]; // If a UNI staking rewards contract is in use, withdraw from it if (pool.uniStakeContract != address(0)) { IStakingRewards(pool.uniStakeContract).withdraw(_amount); } user.staked = user.staked.sub(_amount); user.rewardDebt = user.staked.mul(pool.accSurfPerShare).div(1e12); user.uniRewardDebt = user.staked.mul(pool.accUniPerShare).div(1e12); pool.lpToken.safeTransfer(address(msg.sender), _amount); emit Withdraw(msg.sender, _pid, _amount); } // Convenience function to allow users to migrate all of their staked SURF-ETH LP tokens from Tito to the Whirlpool staking contract after the max supply is hit. Migrating won't work until whirlpool.active() == true function migrateSURFLPtoWhirlpool() public { require(whirlpool.active() == true, "whirlpool not active"); UserInfo storage user = userInfo[0][msg.sender]; uint256 amountToMigrate = user.staked; require(amountToMigrate > 0, "migrate: not good"); updatePool(0); // Claim any pending SURF _claimRewardsFromPool(0, msg.sender); user.staked = 0; user.rewardDebt = 0; poolInfo[0].lpToken.safeApprove(address(whirlpool), 0); poolInfo[0].lpToken.safeApprove(address(whirlpool), amountToMigrate); whirlpool.stakeFor(msg.sender, amountToMigrate); emit Withdraw(msg.sender, 0, amountToMigrate); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { UserInfo storage user = userInfo[_pid][msg.sender]; uint256 staked = user.staked; require(staked > 0, "no tokens"); PoolInfo memory pool = poolInfo[_pid]; // If a UNI staking rewards contract is in use, withdraw from it if (pool.uniStakeContract != address(0)) { IStakingRewards(pool.uniStakeContract).withdraw(staked); } user.staked = 0; user.rewardDebt = 0; user.uniRewardDebt = 0; pool.lpToken.safeTransfer(address(msg.sender), staked); emit EmergencyWithdraw(msg.sender, _pid, staked); } // Internal function to safely transfer SURF in case there is a rounding error function _safeSurfTransfer(address _to, uint256 _amount) internal { uint256 surfBalance = surf.balanceOf(address(this)); if (_amount > surfBalance) _amount = surfBalance; surf.transfer(_to, _amount); } // Creates the SURF-ETH Uniswap pool and adds the initial liqudity that will be permanently locked. Can be called by anyone, but no sooner than 500 blocks after launch. function activateSurfPool() public { require(surfPoolActive == false, "already active"); require(block.number > startBlock + SOFT_LAUNCH_DURATION.div(2), "too soon"); uint256 initialEthLiquidity = address(this).balance; require(initialEthLiquidity > 0, "need ETH"); massUpdatePools(); // The ETH raised from the staking fees collected before surfPoolActive == true is used to seed the ETH side of the SURF-ETH Uniswap pool. // This means that the higher the staking volume during the first 500 blocks, the higher the initial price of SURF if (donatedETH > 0 && donatedETH < initialEthLiquidity) initialEthLiquidity = initialEthLiquidity.sub(donatedETH); // Mint 1,000,000 new SURF to seed the SURF liquidity in the SURF-ETH Uniswap pool uint256 initialSurfLiquidity = 1000000 * 10**18; surf.mint(address(this), initialSurfLiquidity); // Add the liquidity to the SURF-ETH Uniswap pool surf.approve(address(uniswapRouter), initialSurfLiquidity); ( , , uint256 lpTokensReceived) = uniswapRouter.addLiquidityETH{value: initialEthLiquidity}(address(surf), initialSurfLiquidity, 0, 0, address(this), block.timestamp + 5 minutes); // Activate the SURF-ETH pool initialSurfPoolETH = initialEthLiquidity; surfPoolActive = true; // Permanently lock the LP tokens in the SURF contract IERC20(surfPoolAddress).transfer(address(surf), lpTokensReceived); // Buy SURF with all of the donatedETH from partner projects. This SURF will be sent to the Whirlpool staking contract and will start getting distributed to all stakers when the max supply is hit uint256 donatedAmount = donatedETH; uint256 ethBalance = address(this).balance; if (donatedAmount > ethBalance) donatedAmount = ethBalance; if (donatedAmount > 0) { uint256 surfBought = _buySurf(donatedAmount); // Send the SURF rewards to the Whirlpool staking contract surfSentToWhirlpool += surfBought; _safeSurfTransfer(address(whirlpool), surfBought); donatedETH = 0; } emit SurfPoolActive(msg.sender, initialSurfLiquidity, initialEthLiquidity); } // For use by partner teams that are donating to the SURF community. The funds will be used to purchase SURF tokens which will be distributed to stakers once the max supply is hit function donate(address _lpToken) public payable { require(msg.value >= minimumDonationAmount); require(donaters[_lpToken] == address(0)); donatedETH = donatedETH.add(msg.value); donaters[_lpToken] = msg.sender; donations[_lpToken] = msg.value; } // For use by partner teams that donated to the SURF community. The funds can be removed if a beach wasn't created for the specified lp token (meaning the SURF team didn't hold up their end of the agreement) function removeDonation(address _lpToken) public { require(block.number < startBlock); // Donations can only be removed if the beach hasn't been added by the startBlock address returnAddress = donaters[_lpToken]; require(msg.sender == returnAddress); uint256 donationAmount = donations[_lpToken]; require(donationAmount > 0); uint256 ethBalance = address(this).balance; require(donationAmount <= ethBalance); // Only refund the donation if the beach wasn't created require(existingPools[_lpToken] != true); donatedETH = donatedETH.sub(donationAmount); donaters[_lpToken] = address(0); donations[_lpToken] = 0; msg.sender.transfer(donationAmount); } ////////////////////////// // Governance Functions // ////////////////////////// // The following functions can only be called by the owner (the SURF token holder governance contract) // Sets the address of the Whirlpool staking contract that bought SURF gets sent to for distribution to stakers once the max supply is hit function setWhirlpoolContract(Whirlpool _whirlpool) public onlyOwner { whirlpool = _whirlpool; } // Add a new LP Token pool function addPool(address _token, address _lpToken, uint256 _apr, bool _requireDonation) public onlyOwner { require(surf.maxSupplyHit() != true); require(existingPools[_lpToken] != true, "pool exists"); require(_requireDonation != true || donations[_lpToken] >= minimumDonationAmount, "must donate"); _addPool(_token, _lpToken); if (_apr != DEFAULT_APR) poolInfo[poolInfo.length-1].apr = _apr; } // Update the given pool's APR function setApr(uint256 _pid, uint256 _apr) public onlyOwner { require(surf.maxSupplyHit() != true); updatePool(_pid); poolInfo[_pid].apr = _apr; } // Add a contract to the whitelist so that it can interact with Tito. This is needed for the Aegis pool contract to be able to stake on behalf of everyone in the pool. // We want limited interaction from contracts due to the growing "flash loan" trend that can be used to dramatically manipulate a token's price in a single block. function addToWhitelist(address _contractAddress) public onlyOwner { contractWhitelist[_contractAddress] = true; } // Remove a contract from the whitelist function removeFromWhitelist(address _contractAddress) public onlyOwner { contractWhitelist[_contractAddress] = false; } }
pragma solidity ^0.6.12; interface StakingRewardsFactory { function stakingRewardsInfoByStakingToken(address) external view returns (address, uint256); } interface IStakingRewards { // Views function lastTimeRewardApplicable() external view returns (uint256); function rewardPerToken() external view returns (uint256); function earned(address account) external view returns (uint256); function getRewardForDuration() external view returns (uint256); function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); // Mutative function stake(uint256 amount) external; function withdraw(uint256 amount) external; function getReward() external; function exit() external; }
/* _____ __ ______ ______ ___________ _____ _ ______________ / ___// / / / __ \/ ____/ / ____/ _/ | / / | / | / / ____/ ____/ \__ \/ / / / /_/ / /_ / /_ / // |/ / /| | / |/ / / / __/ ___/ / /_/ / _, _/ __/ _ / __/ _/ // /| / ___ |/ /| / /___/ /___ /____/\____/_/ |_/_/ (_) /_/ /___/_/ |_/_/ |_/_/ |_/\____/_____/ Website: https://surf.finance Created by Proof and sol_dev, with help from Zoma and Mr Fahrenheit Audited by Aegis DAO and Sherlock Security */ pragma solidity ^0.6.12; import './Ownable.sol'; import './SafeMath.sol'; import './SafeERC20.sol'; import './IERC20.sol'; import './IUniswapV2Router02.sol'; import './SURF.sol'; import './Tito.sol'; // The Whirlpool staking contract becomes active after the max supply it hit, and is where SURF-ETH LP token stakers will continue to receive dividends from other projects in the SURF ecosystem contract Whirlpool is Ownable { using SafeMath for uint256; using SafeERC20 for IERC20; // Info of each user struct UserInfo { uint256 staked; // How many SURF-ETH LP tokens the user has staked uint256 rewardDebt; // Reward debt. Works the same as in the Tito contract uint256 claimed; // Tracks the amount of SURF claimed by the user } // The SURF TOKEN! SURF public surf; // The Tito contract Tito public tito; // The SURF-ETH Uniswap LP token IERC20 public surfPool; // The Uniswap v2 Router IUniswapV2Router02 public uniswapRouter = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // WETH IERC20 public weth; // Info of each user that stakes SURF-ETH LP tokens mapping (address => UserInfo) public userInfo; // The amount of SURF sent to this contract before it became active uint256 public initialSurfReward = 0; // 1% of the initialSurfReward will be rewarded to stakers per day for 100 days uint256 public initialSurfRewardPerDay; // How often the initial 1% payouts can be processed uint256 public constant INITIAL_PAYOUT_INTERVAL = 24 hours; // The unstaking fee that is used to increase locked liquidity and reward Whirlpool stakers (1 = 0.1%). Defaults to 10% uint256 public unstakingFee = 100; // The amount of SURF-ETH LP tokens kept by the unstaking fee that will be converted to SURF and distributed to stakers (1 = 0.1%). Defaults to 50% uint256 public unstakingFeeConvertToSurfAmount = 500; // When the first 1% payout can be processed (timestamp). It will be 24 hours after the Whirlpool contract is activated uint256 public startTime; // When the last 1% payout was processed (timestamp) uint256 public lastPayout; // The total amount of pending SURF available for stakers to claim uint256 public totalPendingSurf; // Accumulated SURFs per share, times 1e12. uint256 public accSurfPerShare; // The total amount of SURF-ETH LP tokens staked in the contract uint256 public totalStaked; // Becomes true once the 'activate' function called by the Tito contract when the max SURF supply is hit bool public active = false; event Stake(address indexed user, uint256 amount); event Claim(address indexed user, uint256 surfAmount); event Withdraw(address indexed user, uint256 amount); event SurfRewardAdded(address indexed user, uint256 surfReward); event EthRewardAdded(address indexed user, uint256 ethReward); constructor(SURF _surf, Tito _tito) public { tito = _tito; surf = _surf; surfPool = IERC20(tito.surfPoolAddress()); weth = IERC20(uniswapRouter.WETH()); } receive() external payable { emit EthRewardAdded(msg.sender, msg.value); } function activate() public { require(active != true, "already active"); require(surf.maxSupplyHit() == true, "too soon"); active = true; // Now that the Whirlpool staking contract is active, reward 1% of the initialSurfReward per day for 100 days startTime = block.timestamp + INITIAL_PAYOUT_INTERVAL; // The first payout can be processed 24 hours after activation lastPayout = startTime; initialSurfRewardPerDay = initialSurfReward.div(100); } // The _transfer function in the SURF contract calls this to let the Whirlpool contract know that it received the specified amount of SURF to be distributed to stakers function addSurfReward(address _from, uint256 _amount) public { require(msg.sender == address(surf), "not surf contract"); require(tito.surfPoolActive() == true, "no surf pool"); require(_amount > 0, "no surf"); if (active != true || totalStaked == 0) { initialSurfReward = initialSurfReward.add(_amount); } else { totalPendingSurf = totalPendingSurf.add(_amount); accSurfPerShare = accSurfPerShare.add(_amount.mul(1e12).div(totalStaked)); } emit SurfRewardAdded(_from, _amount); } // Allows external sources to add ETH to the contract which is used to buy and then distribute SURF to stakers function addEthReward() public payable { require(tito.surfPoolActive() == true, "no surf pool"); // We will purchase SURF with all of the ETH in the contract in case some was sent directly to the contract instead of using addEthReward uint256 ethBalance = address(this).balance; require(ethBalance > 0, "no eth"); // Use the ETH to buyback SURF which will be distributed to stakers _buySurf(ethBalance); // The _transfer function in the SURF contract calls the Whirlpool contract's updateSurfReward function so we don't need to update the balances after buying the SURF emit EthRewardAdded(msg.sender, msg.value); } // Internal function to buy back SURF with the amount of ETH specified function _buySurf(uint256 _amount) internal { uint256 deadline = block.timestamp + 5 minutes; address[] memory surfPath = new address[](2); surfPath[0] = address(weth); surfPath[1] = address(surf); uniswapRouter.swapExactETHForTokens{value: _amount}(0, surfPath, address(this), deadline); } // Handles paying out the initialSurfReward over 100 days function _processInitialPayouts() internal { if (active != true || block.timestamp < startTime || initialSurfReward == 0 || totalStaked == 0) return; // How many days since last payout? uint256 daysSinceLastPayout = (block.timestamp - lastPayout) / INITIAL_PAYOUT_INTERVAL; // If less than 1, don't do anything if (daysSinceLastPayout == 0) return; // Work out how many payouts have been missed uint256 nextPayoutNumber = (block.timestamp - startTime) / INITIAL_PAYOUT_INTERVAL; uint256 previousPayoutNumber = nextPayoutNumber - daysSinceLastPayout; // Calculate how much additional reward we have to hand out uint256 surfReward = rewardAtPayout(nextPayoutNumber) - rewardAtPayout(previousPayoutNumber); if (surfReward > initialSurfReward) surfReward = initialSurfReward; initialSurfReward = initialSurfReward.sub(surfReward); // Payout the surfReward to the stakers totalPendingSurf = totalPendingSurf.add(surfReward); accSurfPerShare = accSurfPerShare.add(surfReward.mul(1e12).div(totalStaked)); // Update lastPayout time lastPayout += (daysSinceLastPayout * INITIAL_PAYOUT_INTERVAL); } // Handles claiming the user's pending SURF rewards function _claimReward(address _user) internal { UserInfo storage user = userInfo[_user]; if (user.staked > 0) { uint256 pendingSurfReward = user.staked.mul(accSurfPerShare).div(1e12).sub(user.rewardDebt); if (pendingSurfReward > 0) { totalPendingSurf = totalPendingSurf.sub(pendingSurfReward); user.claimed += pendingSurfReward; _safeSurfTransfer(_user, pendingSurfReward); emit Claim(_user, pendingSurfReward); } } } // Stake SURF-ETH LP tokens to get rewarded with more SURF function stake(uint256 _amount) public { stakeFor(msg.sender, _amount); } // Stake SURF-ETH LP tokens on behalf of another address function stakeFor(address _user, uint256 _amount) public { require(active == true, "not active"); require(_amount > 0, "stake something"); _processInitialPayouts(); // Claim any pending SURF _claimReward(_user); surfPool.safeTransferFrom(address(msg.sender), address(this), _amount); UserInfo storage user = userInfo[_user]; totalStaked = totalStaked.add(_amount); user.staked = user.staked.add(_amount); user.rewardDebt = user.staked.mul(accSurfPerShare).div(1e12); emit Stake(_user, _amount); } // Claim earned SURF. Claiming won't work until active == true function claim() public { require(active == true, "not active"); UserInfo storage user = userInfo[msg.sender]; require(user.staked > 0, "no stake"); _processInitialPayouts(); // Claim any pending SURF _claimReward(msg.sender); user.rewardDebt = user.staked.mul(accSurfPerShare).div(1e12); } // Unstake and withdraw SURF-ETH LP tokens and any pending SURF rewards. There is a 10% unstaking fee, meaning the user will only receive 90% of their LP tokens back. // For the LP tokens kept by the unstaking fee, 50% will get locked forever in the SURF contract, and 50% will get converted to SURF and distributed to stakers. function withdraw(uint256 _amount) public { require(active == true, "not active"); UserInfo storage user = userInfo[msg.sender]; require(_amount > 0 && user.staked >= _amount, "withdraw: not good"); _processInitialPayouts(); uint256 unstakingFeeAmount = _amount.mul(unstakingFee).div(1000); uint256 remainingUserAmount = _amount.sub(unstakingFeeAmount); // Half of the LP tokens kept by the unstaking fee will be locked forever in the SURF contract, the other half will be converted to SURF and distributed to stakers uint256 lpTokensToConvertToSurf = unstakingFeeAmount.mul(unstakingFeeConvertToSurfAmount).div(1000); uint256 lpTokensToLock = unstakingFeeAmount.sub(lpTokensToConvertToSurf); // Remove the liquidity from the Uniswap SURF-ETH pool and buy SURF with the ETH received // The _transfer function in the SURF.sol contract automatically calls whirlpool.addSurfReward() so we don't have to in this function if (lpTokensToConvertToSurf > 0) { surfPool.safeApprove(address(uniswapRouter), lpTokensToConvertToSurf); uniswapRouter.removeLiquidityETHSupportingFeeOnTransferTokens(address(surf), lpTokensToConvertToSurf, 0, 0, address(this), block.timestamp + 5 minutes); addEthReward(); } // Permanently lock the LP tokens in the SURF contract if (lpTokensToLock > 0) surfPool.transfer(address(surf), lpTokensToLock); // Claim any pending SURF _claimReward(msg.sender); totalStaked = totalStaked.sub(_amount); user.staked = user.staked.sub(_amount); surfPool.safeTransfer(address(msg.sender), remainingUserAmount); user.rewardDebt = user.staked.mul(accSurfPerShare).div(1e12); emit Withdraw(msg.sender, remainingUserAmount); } // Internal function to safely transfer SURF in case there is a rounding error function _safeSurfTransfer(address _to, uint256 _amount) internal { uint256 surfBal = surf.balanceOf(address(this)); if (_amount > surfBal) { surf.transfer(_to, surfBal); } else { surf.transfer(_to, _amount); } } // Sets the unstaking fee. Can't be higher than 50%. _convertToSurfAmount is the % of the LP tokens from the unstaking fee that will be converted to SURF and distributed to stakers. // unstakingFee - unstakingFeeConvertToSurfAmount = The % of the LP tokens from the unstaking fee that will be permanently locked in the SURF contract function setUnstakingFee(uint256 _unstakingFee, uint256 _convertToSurfAmount) public onlyOwner { require(_unstakingFee <= 500, "over 50%"); require(_convertToSurfAmount <= 1000, "bad amount"); unstakingFee = _unstakingFee; unstakingFeeConvertToSurfAmount = _convertToSurfAmount; } // Function to recover ERC20 tokens accidentally sent to the contract. // SURF and SURF-ETH LP tokens (the only 2 ERC2O's that should be in this contract) can't be withdrawn this way. function recoverERC20(address _tokenAddress) public onlyOwner { require(_tokenAddress != address(surf) && _tokenAddress != address(surfPool)); IERC20 token = IERC20(_tokenAddress); uint256 tokenBalance = token.balanceOf(address(this)); token.transfer(msg.sender, tokenBalance); } function payoutNumber() public view returns (uint256) { if (block.timestamp < startTime) return 0; uint256 payout = (block.timestamp - startTime).div(INITIAL_PAYOUT_INTERVAL); if (payout > 100) return 100; else return payout; } function timeUntilNextPayout() public view returns (uint256) { if (initialSurfReward == 0) return 0; else { uint256 payout = payoutNumber(); uint256 nextPayout = startTime.add((payout + 1).mul(INITIAL_PAYOUT_INTERVAL)); return nextPayout - block.timestamp; } } function rewardAtPayout(uint256 _payoutNumber) public view returns (uint256) { if (_payoutNumber == 0) return 0; return initialSurfRewardPerDay * _payoutNumber; } function getAllInfoFor(address _user) external view returns (bool isActive, uint256[12] memory info) { isActive = active; info[0] = surf.balanceOf(address(this)); info[1] = initialSurfReward; info[2] = totalPendingSurf; info[3] = startTime; info[4] = lastPayout; info[5] = totalStaked; info[6] = surf.balanceOf(_user); if (tito.surfPoolActive()) { info[7] = surfPool.balanceOf(_user); info[8] = surfPool.allowance(_user, address(this)); } info[9] = userInfo[_user].staked; info[10] = userInfo[_user].staked.mul(accSurfPerShare).div(1e12).sub(userInfo[_user].rewardDebt); info[11] = userInfo[_user].claimed; } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract Tito","name":"_tito","type":"address"},{"internalType":"contract Whirlpool","name":"_whirlpool","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"}],"name":"depositInto","outputs":[{"internalType":"uint256","name":"lpReceived","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_pid","type":"uint256"}],"name":"giveFor","outputs":[{"internalType":"uint256","name":"lpReceived","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"stake","outputs":[{"internalType":"uint256","name":"lpReceived","type":"uint256"}],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
6080604052600080546001600160a01b031916737a250d5630b4cf539739df2c5dacb4c659f2488d17905534801561003657600080fd5b5060405161136e38038061136e8339818101604052604081101561005957600080fd5b508051602090910151600180546001600160a01b039384166001600160a01b031991821617909155600280549390921692169190911790556112ce806100a06000396000f3fe6080604052600436106100385760003560e01c80633a4b66f11461005157806357d14ceb1461006b5780635e65266d146100885761004c565b3661004c573332141561004a57600080fd5b005b600080fd5b6100596100a5565b60408051918252519081900360200190f35b6100596004803603602081101561008157600080fd5b5035610363565b6100596004803603602081101561009e57600080fd5b503561053a565b6000803411801561012c5750600260009054906101000a90046001600160a01b03166001600160a01b03166302fb0c5e6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100ff57600080fd5b505afa158015610113573d6000803e3d6000fd5b505050506040513d602081101561012957600080fd5b50515b61013557600080fd5b60025460408051631891036b60e11b8152905161021e926001600160a01b03169163312206d6916004808301926020929190829003018186803b15801561017b57600080fd5b505afa15801561018f573d6000803e3d6000fd5b505050506040513d60208110156101a557600080fd5b50516002546040805163355593fd60e21b815290516001600160a01b039092169163d5564ff491600480820192602092909190829003018186803b1580156101ec57600080fd5b505afa158015610200573d6000803e3d6000fd5b505050506040513d602081101561021657600080fd5b5051346106ed565b6002546040805163355593fd60e21b815290519293506102ab926001600160a01b0390921691600091839163d5564ff491600480820192602092909190829003018186803b15801561026f57600080fd5b505afa158015610283573d6000803e3d6000fd5b505050506040513d602081101561029957600080fd5b50516001600160a01b031691906109e3565b6002546040805163355593fd60e21b815290516102f5926001600160a01b0316918491839163d5564ff4916004808301926020929190829003018186803b15801561026f57600080fd5b600254604080516305dc812160e31b81523360048201526024810184905290516001600160a01b0390921691632ee409089160448082019260009290919082900301818387803b15801561034857600080fd5b505af115801561035c573d6000803e3d6000fd5b5050505090565b600080341180156103ec5750600160009054906101000a90046001600160a01b03166001600160a01b031663081e3eda6040518163ffffffff1660e01b815260040160206040518083038186803b1580156103bd57600080fd5b505afa1580156103d1573d6000803e3d6000fd5b505050506040513d60208110156103e757600080fd5b505182105b6103f557600080fd5b60015460408051631526fe2760e01b815260048101859052905160009283926001600160a01b0390911691631526fe279160248082019260e092909190829003018186803b15801561044657600080fd5b505afa15801561045a573d6000803e3d6000fd5b505050506040513d60e081101561047057600080fd5b50805160209091015190925090506104898282346106ed565b6001549093506104a7906001600160a01b03838116911660006109e3565b6001546104c1906001600160a01b038381169116856109e3565b60015460408051637ce2845760e11b8152600481018790523360248201526044810186905290516001600160a01b039092169163f9c508ae9160648082019260009290919082900301818387803b15801561051b57600080fd5b505af115801561052f573d6000803e3d6000fd5b505050505050919050565b600080341180156105c35750600160009054906101000a90046001600160a01b03166001600160a01b031663081e3eda6040518163ffffffff1660e01b815260040160206040518083038186803b15801561059457600080fd5b505afa1580156105a8573d6000803e3d6000fd5b505050506040513d60208110156105be57600080fd5b505182105b6105cc57600080fd5b60015460408051631526fe2760e01b815260048101859052905160009283926001600160a01b0390911691631526fe279160248082019260e092909190829003018186803b15801561061d57600080fd5b505afa158015610631573d6000803e3d6000fd5b505050506040513d60e081101561064757600080fd5b50805160209091015190925090506106608282346106ed565b9250806001600160a01b031663a9059cbb33856040518363ffffffff1660e01b815260040180836001600160a01b0316815260200182815260200192505050602060405180830381600087803b1580156106b957600080fd5b505af11580156106cd573d6000803e3d6000fd5b505050506040513d60208110156106e357600080fd5b5092949350505050565b60008082116106fb57600080fd5b604080516002808252606080830184529260208301908036833701905050905060008054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561076757600080fd5b505afa15801561077b573d6000803e3d6000fd5b505050506040513d602081101561079157600080fd5b5051815182906000906107a057fe5b60200260200101906001600160a01b031690816001600160a01b03168152505084816001815181106107ce57fe5b6001600160a01b03928316602091820292909201015260005416637ff36ab560028504600084304261012c016040518663ffffffff1660e01b81526004018085815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b8381101561086457818101518382015260200161084c565b50505050905001955050505050506000604051808303818588803b15801561088b57600080fd5b505af115801561089f573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f1916820160405260208110156108c957600080fd5b81019080805160405193929190846401000000008211156108e957600080fd5b9083019060208201858111156108fe57600080fd5b825186602082028301116401000000008211171561091b57600080fd5b82525081516020918201928201910280838360005b83811015610948578181015183820152602001610930565b50505050905001604052505050506109da8585876001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156109a857600080fd5b505afa1580156109bc573d6000803e3d6000fd5b505050506040513d60208110156109d257600080fd5b505147610afb565b95945050505050565b801580610a69575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b158015610a3b57600080fd5b505afa158015610a4f573d6000803e3d6000fd5b505050506040513d6020811015610a6557600080fd5b5051155b610aa45760405162461bcd60e51b81526004018080602001828103825260368152602001806112636036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052610af6908490610f8c565b505050565b60008083118015610b0c5750600082115b610b1557600080fd5b6000849050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015610b5657600080fd5b505afa158015610b6a573d6000803e3d6000fd5b505050506040513d6060811015610b8057600080fd5b50805160209182015160408051630dfe168160e01b815290516dffffffffffffffffffffffffffff93841696509290911693506000926001600160a01b03808d169390881692630dfe1681926004808301939192829003018186803b158015610be857600080fd5b505afa158015610bfc573d6000803e3d6000fd5b505050506040513d6020811015610c1257600080fd5b50516001600160a01b0316149050600081610c2d5783610c2f565b825b82610c3a5783610c3c565b845b670de0b6b3a76400000281610c4d57fe5b60008054929091049250610c6f916001600160a01b038d8116929116906109e3565b8688670de0b6b3a76400000281610c8257fe5b04811115610d6e5760008189670de0b6b3a76400000281610c9f57fe5b6000549190049150610cbe906001600160a01b038d811691168b6109e3565b600080546040805163f305d71960e01b81526001600160a01b038f81166004830152602482018e905260448201859052606482019490945230608482015261012c420160a48201529051929091169163f305d71991849160c480830192606092919082900301818588803b158015610d3557600080fd5b505af1158015610d49573d6000803e3d6000fd5b50505050506040513d6060811015610d6057600080fd5b50604001519650610e4d9050565b60008782670de0b6b3a76400000281610d8357fe5b6000549190049150610da2906001600160a01b038d81169116836109e3565b600080546040805163f305d71960e01b81526001600160a01b038f811660048301526024820186905260448201859052606482019490945230608482015261012c420160a48201529051929091169163f305d719918b9160c480830192606092919082900301818588803b158015610e1957600080fd5b505af1158015610e2d573d6000803e3d6000fd5b50505050506040513d6060811015610e4457600080fd5b50604001519650505b604080516370a0823160e01b8152306004820152905147916000916001600160a01b038e16916370a08231916024808301926020929190829003018186803b158015610e9857600080fd5b505afa158015610eac573d6000803e3d6000fd5b505050506040513d6020811015610ec257600080fd5b505190508115610efb57604051339083156108fc029084906000818181858888f19350505050158015610ef9573d6000803e3d6000fd5b505b8015610f7d576040805163a9059cbb60e01b81523360048201526024810183905290516001600160a01b038e169163a9059cbb9160448083019260209291908290030181600087803b158015610f5057600080fd5b505af1158015610f64573d6000803e3d6000fd5b505050506040513d6020811015610f7a57600080fd5b50505b50505050505050949350505050565b6060610fe1826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661103d9092919063ffffffff16565b805190915015610af65780806020019051602081101561100057600080fd5b5051610af65760405162461bcd60e51b815260040180806020018281038252602a815260200180611239602a913960400191505060405180910390fd5b606061104c8484600085611054565b949350505050565b606061105f856111ff565b6110b0576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b602083106110ef5780518252601f1990920191602091820191016110d0565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611151576040519150601f19603f3d011682016040523d82523d6000602084013e611156565b606091505b5091509150811561116a57915061104c9050565b80511561117a5780518082602001fd5b8360405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156111c45781810151838201526020016111ac565b50505050905090810190601f1680156111f15780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081811480159061104c57505015159291505056fe5361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a26469706673582212204a920096fdb675259f5f293ae71ff3db294e59014fc3bbf0f9f845463c2d503164736f6c634300060c003300000000000000000000000065e5bc985b8399b338c3c55ff1e3c048586d50ca000000000000000000000000999b1e6edcb412b59ecf0c5e14c20948ce81f40b
Deployed Bytecode
0x6080604052600436106100385760003560e01c80633a4b66f11461005157806357d14ceb1461006b5780635e65266d146100885761004c565b3661004c573332141561004a57600080fd5b005b600080fd5b6100596100a5565b60408051918252519081900360200190f35b6100596004803603602081101561008157600080fd5b5035610363565b6100596004803603602081101561009e57600080fd5b503561053a565b6000803411801561012c5750600260009054906101000a90046001600160a01b03166001600160a01b03166302fb0c5e6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100ff57600080fd5b505afa158015610113573d6000803e3d6000fd5b505050506040513d602081101561012957600080fd5b50515b61013557600080fd5b60025460408051631891036b60e11b8152905161021e926001600160a01b03169163312206d6916004808301926020929190829003018186803b15801561017b57600080fd5b505afa15801561018f573d6000803e3d6000fd5b505050506040513d60208110156101a557600080fd5b50516002546040805163355593fd60e21b815290516001600160a01b039092169163d5564ff491600480820192602092909190829003018186803b1580156101ec57600080fd5b505afa158015610200573d6000803e3d6000fd5b505050506040513d602081101561021657600080fd5b5051346106ed565b6002546040805163355593fd60e21b815290519293506102ab926001600160a01b0390921691600091839163d5564ff491600480820192602092909190829003018186803b15801561026f57600080fd5b505afa158015610283573d6000803e3d6000fd5b505050506040513d602081101561029957600080fd5b50516001600160a01b031691906109e3565b6002546040805163355593fd60e21b815290516102f5926001600160a01b0316918491839163d5564ff4916004808301926020929190829003018186803b15801561026f57600080fd5b600254604080516305dc812160e31b81523360048201526024810184905290516001600160a01b0390921691632ee409089160448082019260009290919082900301818387803b15801561034857600080fd5b505af115801561035c573d6000803e3d6000fd5b5050505090565b600080341180156103ec5750600160009054906101000a90046001600160a01b03166001600160a01b031663081e3eda6040518163ffffffff1660e01b815260040160206040518083038186803b1580156103bd57600080fd5b505afa1580156103d1573d6000803e3d6000fd5b505050506040513d60208110156103e757600080fd5b505182105b6103f557600080fd5b60015460408051631526fe2760e01b815260048101859052905160009283926001600160a01b0390911691631526fe279160248082019260e092909190829003018186803b15801561044657600080fd5b505afa15801561045a573d6000803e3d6000fd5b505050506040513d60e081101561047057600080fd5b50805160209091015190925090506104898282346106ed565b6001549093506104a7906001600160a01b03838116911660006109e3565b6001546104c1906001600160a01b038381169116856109e3565b60015460408051637ce2845760e11b8152600481018790523360248201526044810186905290516001600160a01b039092169163f9c508ae9160648082019260009290919082900301818387803b15801561051b57600080fd5b505af115801561052f573d6000803e3d6000fd5b505050505050919050565b600080341180156105c35750600160009054906101000a90046001600160a01b03166001600160a01b031663081e3eda6040518163ffffffff1660e01b815260040160206040518083038186803b15801561059457600080fd5b505afa1580156105a8573d6000803e3d6000fd5b505050506040513d60208110156105be57600080fd5b505182105b6105cc57600080fd5b60015460408051631526fe2760e01b815260048101859052905160009283926001600160a01b0390911691631526fe279160248082019260e092909190829003018186803b15801561061d57600080fd5b505afa158015610631573d6000803e3d6000fd5b505050506040513d60e081101561064757600080fd5b50805160209091015190925090506106608282346106ed565b9250806001600160a01b031663a9059cbb33856040518363ffffffff1660e01b815260040180836001600160a01b0316815260200182815260200192505050602060405180830381600087803b1580156106b957600080fd5b505af11580156106cd573d6000803e3d6000fd5b505050506040513d60208110156106e357600080fd5b5092949350505050565b60008082116106fb57600080fd5b604080516002808252606080830184529260208301908036833701905050905060008054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b815260040160206040518083038186803b15801561076757600080fd5b505afa15801561077b573d6000803e3d6000fd5b505050506040513d602081101561079157600080fd5b5051815182906000906107a057fe5b60200260200101906001600160a01b031690816001600160a01b03168152505084816001815181106107ce57fe5b6001600160a01b03928316602091820292909201015260005416637ff36ab560028504600084304261012c016040518663ffffffff1660e01b81526004018085815260200180602001846001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b8381101561086457818101518382015260200161084c565b50505050905001955050505050506000604051808303818588803b15801561088b57600080fd5b505af115801561089f573d6000803e3d6000fd5b50505050506040513d6000823e601f3d908101601f1916820160405260208110156108c957600080fd5b81019080805160405193929190846401000000008211156108e957600080fd5b9083019060208201858111156108fe57600080fd5b825186602082028301116401000000008211171561091b57600080fd5b82525081516020918201928201910280838360005b83811015610948578181015183820152602001610930565b50505050905001604052505050506109da8585876001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b0316815260200191505060206040518083038186803b1580156109a857600080fd5b505afa1580156109bc573d6000803e3d6000fd5b505050506040513d60208110156109d257600080fd5b505147610afb565b95945050505050565b801580610a69575060408051636eb1769f60e11b81523060048201526001600160a01b03848116602483015291519185169163dd62ed3e91604480820192602092909190829003018186803b158015610a3b57600080fd5b505afa158015610a4f573d6000803e3d6000fd5b505050506040513d6020811015610a6557600080fd5b5051155b610aa45760405162461bcd60e51b81526004018080602001828103825260368152602001806112636036913960400191505060405180910390fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663095ea7b360e01b179052610af6908490610f8c565b505050565b60008083118015610b0c5750600082115b610b1557600080fd5b6000849050600080826001600160a01b0316630902f1ac6040518163ffffffff1660e01b815260040160606040518083038186803b158015610b5657600080fd5b505afa158015610b6a573d6000803e3d6000fd5b505050506040513d6060811015610b8057600080fd5b50805160209182015160408051630dfe168160e01b815290516dffffffffffffffffffffffffffff93841696509290911693506000926001600160a01b03808d169390881692630dfe1681926004808301939192829003018186803b158015610be857600080fd5b505afa158015610bfc573d6000803e3d6000fd5b505050506040513d6020811015610c1257600080fd5b50516001600160a01b0316149050600081610c2d5783610c2f565b825b82610c3a5783610c3c565b845b670de0b6b3a76400000281610c4d57fe5b60008054929091049250610c6f916001600160a01b038d8116929116906109e3565b8688670de0b6b3a76400000281610c8257fe5b04811115610d6e5760008189670de0b6b3a76400000281610c9f57fe5b6000549190049150610cbe906001600160a01b038d811691168b6109e3565b600080546040805163f305d71960e01b81526001600160a01b038f81166004830152602482018e905260448201859052606482019490945230608482015261012c420160a48201529051929091169163f305d71991849160c480830192606092919082900301818588803b158015610d3557600080fd5b505af1158015610d49573d6000803e3d6000fd5b50505050506040513d6060811015610d6057600080fd5b50604001519650610e4d9050565b60008782670de0b6b3a76400000281610d8357fe5b6000549190049150610da2906001600160a01b038d81169116836109e3565b600080546040805163f305d71960e01b81526001600160a01b038f811660048301526024820186905260448201859052606482019490945230608482015261012c420160a48201529051929091169163f305d719918b9160c480830192606092919082900301818588803b158015610e1957600080fd5b505af1158015610e2d573d6000803e3d6000fd5b50505050506040513d6060811015610e4457600080fd5b50604001519650505b604080516370a0823160e01b8152306004820152905147916000916001600160a01b038e16916370a08231916024808301926020929190829003018186803b158015610e9857600080fd5b505afa158015610eac573d6000803e3d6000fd5b505050506040513d6020811015610ec257600080fd5b505190508115610efb57604051339083156108fc029084906000818181858888f19350505050158015610ef9573d6000803e3d6000fd5b505b8015610f7d576040805163a9059cbb60e01b81523360048201526024810183905290516001600160a01b038e169163a9059cbb9160448083019260209291908290030181600087803b158015610f5057600080fd5b505af1158015610f64573d6000803e3d6000fd5b505050506040513d6020811015610f7a57600080fd5b50505b50505050505050949350505050565b6060610fe1826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661103d9092919063ffffffff16565b805190915015610af65780806020019051602081101561100057600080fd5b5051610af65760405162461bcd60e51b815260040180806020018281038252602a815260200180611239602a913960400191505060405180910390fd5b606061104c8484600085611054565b949350505050565b606061105f856111ff565b6110b0576040805162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015290519081900360640190fd5b60006060866001600160a01b031685876040518082805190602001908083835b602083106110ef5780518252601f1990920191602091820191016110d0565b6001836020036101000a03801982511681845116808217855250505050505090500191505060006040518083038185875af1925050503d8060008114611151576040519150601f19603f3d011682016040523d82523d6000602084013e611156565b606091505b5091509150811561116a57915061104c9050565b80511561117a5780518082602001fd5b8360405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b838110156111c45781810151838201526020016111ac565b50505050905090810190601f1680156111f15780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081811480159061104c57505015159291505056fe5361666545524332303a204552433230206f7065726174696f6e20646964206e6f7420737563636565645361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f20746f206e6f6e2d7a65726f20616c6c6f77616e6365a26469706673582212204a920096fdb675259f5f293ae71ff3db294e59014fc3bbf0f9f845463c2d503164736f6c634300060c0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000065e5bc985b8399b338c3c55ff1e3c048586d50ca000000000000000000000000999b1e6edcb412b59ecf0c5e14c20948ce81f40b
-----Decoded View---------------
Arg [0] : _tito (address): 0x65E5BC985b8399B338C3C55ff1e3c048586d50ca
Arg [1] : _whirlpool (address): 0x999b1e6EDCb412b59ECF0C5e14c20948Ce81F40b
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 00000000000000000000000065e5bc985b8399b338c3c55ff1e3c048586d50ca
Arg [1] : 000000000000000000000000999b1e6edcb412b59ecf0c5e14c20948ce81f40b
Deployed Bytecode Sourcemap
190:3686:1:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;594:10;608:9;594:23;;586:32;;;;;;190:3686;;;;;1433:418;;;:::i;:::-;;;;;;;;;;;;;;;;635:452;;;;;;;;;;;;;;;;-1:-1:-1;635:452:1;;:::i;1097:326::-;;;;;;;;;;;;;;;;-1:-1:-1;1097:326:1;;:::i;1433:418::-;1476:18;1526:1;1514:9;:13;:35;;;;;1531:9;;;;;;;;;-1:-1:-1;;;;;1531:9:1;-1:-1:-1;;;;;1531:16:1;;:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1531:18:1;1514:35;1506:44;;;;;;1602:9;;:16;;;-1:-1:-1;;;1602:16:1;;;;1582:71;;-1:-1:-1;;;;;1602:9:1;;:14;;:16;;;;;;;;;;;;;;:9;:16;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1602:16:1;1621:9;;:20;;;-1:-1:-1;;;1621:20:1;;;;-1:-1:-1;;;;;1621:9:1;;;;:18;;:20;;;;;1602:16;;1621:20;;;;;;;;:9;:20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1621:20:1;1643:9;1582:12;:71::i;:::-;1704:9;;1663:20;;;-1:-1:-1;;;1663:20:1;;;;1569:84;;-1:-1:-1;1663:55:1;;-1:-1:-1;;;;;1704:9:1;;;;;;;;1663:18;;:20;;;;;;;;;;;;;;;1704:9;1663:20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1663:20:1;-1:-1:-1;;;;;1663:32:1;;:55;:32;:55::i;:::-;1769:9;;1728:20;;;-1:-1:-1;;;1728:20:1;;;;:64;;-1:-1:-1;;;;;1769:9:1;;1781:10;;1769:9;;1728:18;;:20;;;;;;;;;;;;;;1769:9;1728:20;;;;;;;;;;:64;1802:9;;:42;;;-1:-1:-1;;;1802:42:1;;1821:10;1802:42;;;;;;;;;;;;-1:-1:-1;;;;;1802:9:1;;;;:18;;:42;;;;;:9;;:42;;;;;;;;:9;;:42;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1433:418;:::o;635:452::-;696:18;746:1;734:9;:13;:41;;;;;758:4;;;;;;;;;-1:-1:-1;;;;;758:4:1;-1:-1:-1;;;;;758:15:1;;:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;758:17:1;751:24;;734:41;726:50;;;;;;837:4;;:19;;;-1:-1:-1;;;837:19:1;;;;;;;;;;796:13;;;;-1:-1:-1;;;;;837:4:1;;;;:13;;:19;;;;;;;;;;;;;;;:4;:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;837:19:1;;;;;;;;;-1:-1:-1;837:19:1;-1:-1:-1;888:38:1;837:19;;916:9;888:12;:38::i;:::-;962:4;;875:51;;-1:-1:-1;936:35:1;;-1:-1:-1;;;;;936:17:1;;;;962:4;;936:17;:35::i;:::-;1007:4;;981:44;;-1:-1:-1;;;;;981:17:1;;;;1007:4;1014:10;981:17;:44::i;:::-;1035:4;;:45;;;-1:-1:-1;;;1035:45:1;;;;;;;;1057:10;1035:45;;;;;;;;;;;;-1:-1:-1;;;;;1035:4:1;;;;:15;;:45;;;;;:4;;:45;;;;;;;;:4;;:45;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;635:452;;;;;:::o;1097:326::-;1154:18;1204:1;1192:9;:13;:41;;;;;1216:4;;;;;;;;;-1:-1:-1;;;;;1216:4:1;-1:-1:-1;;;;;1216:15:1;;:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1216:17:1;1209:24;;1192:41;1184:50;;;;;;1287:4;;:19;;;-1:-1:-1;;;1287:19:1;;;;;;;;;;1246:13;;;;-1:-1:-1;;;;;1287:4:1;;;;:13;;:19;;;;;;;;;;;;;;;:4;:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1287:19:1;;;;;;;;;-1:-1:-1;1287:19:1;-1:-1:-1;1330:38:1;1287:19;;1358:9;1330:12;:38::i;:::-;1317:51;;1378:5;-1:-1:-1;;;;;1378:14:1;;1393:10;1405;1378:38;;;;;;;;;;;;;-1:-1:-1;;;;;1378:38:1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1097:326:1;;;-1:-1:-1;;;;1097:326:1:o;1862:491::-;1948:7;1985:1;1975:7;:11;1967:20;;;;;;2027:16;;;2041:1;2027:16;;;1998:26;2027:16;;;;;1998:26;2027:16;;;;;;;;;;-1:-1:-1;2027:16:1;1998:45;;2068:13;;;;;;;;-1:-1:-1;;;;;2068:13:1;-1:-1:-1;;;;;2068:18:1;;:20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2068:20:1;2053:12;;:9;;2063:1;;2053:12;;;;;;;;;:35;-1:-1:-1;;;;;2053:35:1;;;-1:-1:-1;;;;;2053:35:1;;;;;2121:6;2098:9;2108:1;2098:12;;;;;;;;-1:-1:-1;;;;;2098:30:1;;;:12;;;;;;;;;:30;2138:13;;;:35;2191:1;2181:7;:11;2194:1;2197:9;2216:4;2223:15;2241:9;2223:27;2138:113;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;2138:113:1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;2138:113:1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2138:113:1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2269:77;2276:6;2284:5;2291:6;-1:-1:-1;;;;;2291:16:1;;2316:4;2291:31;;;;;;;;;;;;;-1:-1:-1;;;;;2291:31:1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2291:31:1;2324:21;2269:6;:77::i;:::-;2262:84;1862:491;-1:-1:-1;;;;;1862:491:1:o;1349:613:9:-;1714:10;;;1713:62;;-1:-1:-1;1730:39:9;;;-1:-1:-1;;;1730:39:9;;1754:4;1730:39;;;;-1:-1:-1;;;;;1730:39:9;;;;;;;;;:15;;;;;;:39;;;;;;;;;;;;;;;:15;:39;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1730:39:9;:44;1713:62;1705:150;;;;-1:-1:-1;;;1705:150:9;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1892:62;;;-1:-1:-1;;;;;1892:62:9;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;1892:62:9;-1:-1:-1;;;1892:62:9;;;1865:90;;1885:5;;1865:19;:90::i;:::-;1349:613;;;:::o;2359:1515:1:-;2453:22;2505:1;2495:7;:11;:23;;;;;2517:1;2510:4;:8;2495:23;2487:32;;;;;;2530:20;2576:5;2530:53;;2594:17;2613;2636:5;-1:-1:-1;;;;;2636:17:1;;:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2636:19:1;;;;;;;;2682:14;;-1:-1:-1;;;2682:14:1;;;;2593:62;;;;;-1:-1:-1;2593:62:1;;;;;-1:-1:-1;2665:14:1;;-1:-1:-1;;;;;2682:33:1;;;;:12;;;;;;:14;;;;;2636:19;;2682:14;;;;;:12;:14;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;2682:14:1;-1:-1:-1;;;;;2682:33:1;;;-1:-1:-1;2725:21:1;2682:33;2795;;2819:9;2795:33;;;2807:9;2795:33;2757:9;:33;;2781:9;2757:33;;;2769:9;2757:33;2749:4;:42;:80;;;;;2867:13;;;2749:80;;;;;-1:-1:-1;2840:45:1;;-1:-1:-1;;;;;2840:18:1;;;;2867:13;;;2840:18;:45::i;:::-;2932:4;2922:7;2915:4;:14;:21;;;;;;2899:13;:37;2895:653;;;2952:17;2989:13;2979:7;2972:4;:14;:30;;;;;3043:13;;2972:30;;;;-1:-1:-1;3016:51:1;;-1:-1:-1;;;;;3016:18:1;;;;3043:13;3059:7;3016:18;:51::i;:::-;3105:13;;;:123;;;-1:-1:-1;;;3105:123:1;;-1:-1:-1;;;;;3105:123:1;;;;;;;;;;;;;;;;;;;;;;;;;;3193:4;3105:123;;;;3218:9;3200:15;:27;3105:123;;;;;;:13;;;;;:29;;3142:9;;3105:123;;;;;;;;;;;;;;3142:9;3105:13;:123;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3105:123:1;;;;-1:-1:-1;2895:653:1;;-1:-1:-1;2895:653:1;;3259:19;3304:4;3288:13;3281:4;:20;:27;;;;;3349:13;;3281:27;;;;-1:-1:-1;3322:55:1;;-1:-1:-1;;;;;3322:18:1;;;;3349:13;3281:27;3322:18;:55::i;:::-;3415:13;;;:122;;;-1:-1:-1;;;3415:122:1;;-1:-1:-1;;;;;3415:122:1;;;;;;;;;;;;;;;;;;;;;;;;;;3502:4;3415:122;;;;3527:9;3509:15;:27;3415:122;;;;;;:13;;;;;:29;;3452:4;;3415:122;;;;;;;;;;;;;;3452:4;3415:13;:122;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3415:122:1;;;;-1:-1:-1;;2895:653:1;3640:31;;;-1:-1:-1;;;3640:31:1;;3665:4;3640:31;;;;;;3582:21;;3558;;-1:-1:-1;;;;;3640:16:1;;;;;:31;;;;;;;;;;;;;;:16;:31;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3640:31:1;;-1:-1:-1;3685:17:1;;3681:82;;3718:34;;:10;;:34;;;;;3738:13;;3718:34;;;;3738:13;3718:10;:34;;;;;;;;;;;;;;;;;;;;;3681:82;3776:20;;3772:96;;3812:45;;;-1:-1:-1;;;3812:45:1;;3828:10;3812:45;;;;;;;;;;;;-1:-1:-1;;;;;3812:15:1;;;;;:45;;;;;;;;;;;;;;-1:-1:-1;3812:15:1;:45;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;3772:96:1;2359:1515;;;;;;;;;;;;;:::o;2968:751:9:-;3387:23;3413:69;3441:4;3413:69;;;;;;;;;;;;;;;;;3421:5;-1:-1:-1;;;;;3413:27:9;;;:69;;;;;:::i;:::-;3496:17;;3387:95;;-1:-1:-1;3496:21:9;3492:221;;3636:10;3625:30;;;;;;;;;;;;;;;-1:-1:-1;3625:30:9;3617:85;;;;-1:-1:-1;;;3617:85:9;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3790:194:0;3893:12;3924:53;3947:6;3955:4;3961:1;3964:12;3924:22;:53::i;:::-;3917:60;3790:194;-1:-1:-1;;;;3790:194:0:o;5137:958::-;5267:12;5299:18;5310:6;5299:10;:18::i;:::-;5291:60;;;;;-1:-1:-1;;;5291:60:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;5422:12;5436:23;5463:6;-1:-1:-1;;;;;5463:11:0;5483:8;5494:4;5463:36;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;5463:36:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5421:78;;;;5513:7;5509:580;;;5543:10;-1:-1:-1;5536:17:0;;-1:-1:-1;5536:17:0;5509:580;5654:17;;:21;5650:429;;5912:10;5906:17;5972:15;5959:10;5955:2;5951:19;5944:44;5861:145;6051:12;6044:20;;-1:-1:-1;;;6044:20:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;738:610;798:4;1259:20;;1104:66;1298:23;;;;;;:42;;-1:-1:-1;;1325:15:0;;;1290:51;-1:-1:-1;;738:610:0:o
Swarm Source
ipfs://4a920096fdb675259f5f293ae71ff3db294e59014fc3bbf0f9f845463c2d5031
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.