Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- *
- * _Available since v2.4.0._
- */
- 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.
- *
- * _Available since v2.4.0._
- */
- function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
- // Solidity only automatically asserts when dividing by 0
- 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.
- *
- * _Available since v2.4.0._
- */
- function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
- require(b != 0, errorMessage);
- return a % b;
- }
- }
- contract Sink{
- uint256 constant internal tokenId=1002567;
- uint256 constant internal unlockPeriod=30 days;
- uint256 constant internal unitsPerToken=1e6;
- uint256 constant internal minLocked=100000*unitsPerToken;
- uint256 constant internal unlockRate=1; // in units of 1%.
- using SafeMath for uint256;
- uint256 lockedBalance=0;
- uint256 unlockedBalance=0;
- // Latest of , time of last update of lockedAmount or last time we got sent tokens
- uint256 lastLockedUpdateTimestamp=0;
- mapping(address => bool) public addressCanVote;
- // By default invalid adress = no active request
- address activeWithdrawReqDestination=address(0);
- uint256 activeWithdrawReqAmount=0;
- function() external payable {
- //only accept worldcoin.
- require(msg.tokenid==tokenId,"Send only WRLD");
- // value > 0
- require(msg.tokenvalue>0,"No tokens sent for locking!");
- // for simplicity , sending additional tokens resets the countdown
- lastLockedUpdateTimestamp=now;
- lockedBalance+=msg.value;
- }
- function updateLockedBalance() internal {
- if(now > lastLockedUpdateTimestamp+unlockPeriod && lockedBalance>=minLocked){
- uint256 newlyUnlockedBalance=lockedBalance.mul(unlockRate).div(100);
- uint256 newLockedBalance=lockedBalance.sub(newlyUnlockedBalance);
- lockedBalance=newLockedBalance;
- unlockedBalance=unlockedBalance.add(newlyUnlockedBalance);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement