Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. library SafeMath {
  2. /**
  3. * @dev Returns the addition of two unsigned integers, reverting on
  4. * overflow.
  5. *
  6. * Counterpart to Solidity's `+` operator.
  7. *
  8. * Requirements:
  9. * - Addition cannot overflow.
  10. */
  11. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  12. uint256 c = a + b;
  13. require(c >= a, "SafeMath: addition overflow");
  14.  
  15. return c;
  16. }
  17.  
  18. /**
  19. * @dev Returns the subtraction of two unsigned integers, reverting on
  20. * overflow (when the result is negative).
  21. *
  22. * Counterpart to Solidity's `-` operator.
  23. *
  24. * Requirements:
  25. * - Subtraction cannot overflow.
  26. */
  27. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  28. return sub(a, b, "SafeMath: subtraction overflow");
  29. }
  30.  
  31. /**
  32. * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
  33. * overflow (when the result is negative).
  34. *
  35. * Counterpart to Solidity's `-` operator.
  36. *
  37. * Requirements:
  38. * - Subtraction cannot overflow.
  39. *
  40. * _Available since v2.4.0._
  41. */
  42. function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
  43. require(b <= a, errorMessage);
  44. uint256 c = a - b;
  45.  
  46. return c;
  47. }
  48.  
  49. /**
  50. * @dev Returns the multiplication of two unsigned integers, reverting on
  51. * overflow.
  52. *
  53. * Counterpart to Solidity's `*` operator.
  54. *
  55. * Requirements:
  56. * - Multiplication cannot overflow.
  57. */
  58. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  59. // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
  60. // benefit is lost if 'b' is also tested.
  61. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
  62. if (a == 0) {
  63. return 0;
  64. }
  65.  
  66. uint256 c = a * b;
  67. require(c / a == b, "SafeMath: multiplication overflow");
  68.  
  69. return c;
  70. }
  71.  
  72. /**
  73. * @dev Returns the integer division of two unsigned integers. Reverts on
  74. * division by zero. The result is rounded towards zero.
  75. *
  76. * Counterpart to Solidity's `/` operator. Note: this function uses a
  77. * `revert` opcode (which leaves remaining gas untouched) while Solidity
  78. * uses an invalid opcode to revert (consuming all remaining gas).
  79. *
  80. * Requirements:
  81. * - The divisor cannot be zero.
  82. */
  83. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  84. return div(a, b, "SafeMath: division by zero");
  85. }
  86.  
  87. /**
  88. * @dev Returns the integer division of two unsigned integers. Reverts with custom message on
  89. * division by zero. The result is rounded towards zero.
  90. *
  91. * Counterpart to Solidity's `/` operator. Note: this function uses a
  92. * `revert` opcode (which leaves remaining gas untouched) while Solidity
  93. * uses an invalid opcode to revert (consuming all remaining gas).
  94. *
  95. * Requirements:
  96. * - The divisor cannot be zero.
  97. *
  98. * _Available since v2.4.0._
  99. */
  100. function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
  101. // Solidity only automatically asserts when dividing by 0
  102. require(b > 0, errorMessage);
  103. uint256 c = a / b;
  104. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  105.  
  106. return c;
  107. }
  108.  
  109. /**
  110. * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
  111. * Reverts when dividing by zero.
  112. *
  113. * Counterpart to Solidity's `%` operator. This function uses a `revert`
  114. * opcode (which leaves remaining gas untouched) while Solidity uses an
  115. * invalid opcode to revert (consuming all remaining gas).
  116. *
  117. * Requirements:
  118. * - The divisor cannot be zero.
  119. */
  120. function mod(uint256 a, uint256 b) internal pure returns (uint256) {
  121. return mod(a, b, "SafeMath: modulo by zero");
  122. }
  123.  
  124. /**
  125. * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
  126. * Reverts with custom message when dividing by zero.
  127. *
  128. * Counterpart to Solidity's `%` operator. This function uses a `revert`
  129. * opcode (which leaves remaining gas untouched) while Solidity uses an
  130. * invalid opcode to revert (consuming all remaining gas).
  131. *
  132. * Requirements:
  133. * - The divisor cannot be zero.
  134. *
  135. * _Available since v2.4.0._
  136. */
  137. function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
  138. require(b != 0, errorMessage);
  139. return a % b;
  140. }
  141. }
  142.  
  143. contract Sink{
  144. uint256 constant internal tokenId=1002567;
  145. uint256 constant internal unlockPeriod=30 days;
  146. uint256 constant internal unitsPerToken=1e6;
  147. uint256 constant internal minLocked=100000*unitsPerToken;
  148. uint256 constant internal unlockRate=1; // in units of 1%.
  149. using SafeMath for uint256;
  150. uint256 lockedBalance=0;
  151. uint256 unlockedBalance=0;
  152. // Latest of , time of last update of lockedAmount or last time we got sent tokens
  153. uint256 lastLockedUpdateTimestamp=0;
  154. mapping(address => bool) public addressCanVote;
  155. // By default invalid adress = no active request
  156. address activeWithdrawReqDestination=address(0);
  157. uint256 activeWithdrawReqAmount=0;
  158.  
  159. function() external payable {
  160. //only accept worldcoin.
  161. require(msg.tokenid==tokenId,"Send only WRLD");
  162. // value > 0
  163. require(msg.tokenvalue>0,"No tokens sent for locking!");
  164. // for simplicity , sending additional tokens resets the countdown
  165. lastLockedUpdateTimestamp=now;
  166. lockedBalance+=msg.value;
  167. }
  168.  
  169. function updateLockedBalance() internal {
  170. if(now > lastLockedUpdateTimestamp+unlockPeriod && lockedBalance>=minLocked){
  171. uint256 newlyUnlockedBalance=lockedBalance.mul(unlockRate).div(100);
  172. uint256 newLockedBalance=lockedBalance.sub(newlyUnlockedBalance);
  173. lockedBalance=newLockedBalance;
  174. unlockedBalance=unlockedBalance.add(newlyUnlockedBalance);
  175. }
  176. }
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement