Advertisement
L4zzur

Solidity Lab

Dec 20th, 2022 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | Cryptocurrency | 0 0
  1. // SPDX-License-Identifier: MIT
  2.  
  3. pragma solidity ^0.8.6;
  4.  
  5. contract Bank {
  6.  
  7. mapping(address=>uint256) public balances;
  8. mapping(address=>uint256) public last_refill_times;
  9.  
  10. uint constant SECONDS_PER_DAY = 24 * 60 * 60;
  11. uint constant SECONDS_PER_HOUR = 60 * 60;
  12. uint constant SECONDS_PER_MINUTE = 60;
  13. int constant OFFSET19700101 = 2440588;
  14. uint constant INTEREST_TIME = 60;
  15.  
  16. function Deposit() public payable {
  17. balances[msg.sender] += msg.value;
  18. last_refill_times[msg.sender] = block.timestamp;
  19. }
  20.  
  21. function Withdrawal(uint256 _to_withdraw) external {
  22. require(balances[msg.sender] >= _to_withdraw, "not enough money");
  23. require(_to_withdraw <= 10 ether, "withdrawal more than 10 ETH");
  24. balances[msg.sender] -= _to_withdraw;
  25. (bool success, ) = msg.sender.call{value: _to_withdraw}("");
  26. require(success, "failed to complete");
  27. }
  28.  
  29. function BalanceOf() public view returns(uint256) {
  30. return(balances[msg.sender]);
  31. }
  32.  
  33. function TransferTo(address _to_transfer, uint256 _value) external {
  34. require(balances[msg.sender] >= _value, "not enough money");
  35. require(_value <= 10 ether, "transfer more than 10 ETH");
  36. balances[msg.sender] -= _value;
  37. balances[_to_transfer] += _value;
  38. last_refill_times[_to_transfer] = block.timestamp;
  39. (bool success, ) = msg.sender.call{value: _value}("");
  40. require(success, "failed to complete");
  41. }
  42.  
  43. function Interest() public payable {
  44. uint256 diff = block.timestamp - last_refill_times[msg.sender];
  45. require(diff >= INTEREST_TIME, "time for interest hasn't passed");
  46. balances[msg.sender] += (diff / INTEREST_TIME) * (balances[msg.sender] * 7 / 100);
  47. last_refill_times[msg.sender] = block.timestamp;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement