-
Notifications
You must be signed in to change notification settings - Fork 0
/
jam.sol
101 lines (87 loc) · 3.69 KB
/
jam.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//SPDX-License-Identifier: MIT
pragma solidity ^ 0.8.7;
interface IERC20 {
function totalSupply() external view returns(uint);
function balanceOf(address tokenOwner) external view returns(uint balance);
function transfer(address to, uint tokens) external returns(bool success);
function allowance(address tokenOwner, address spender) external view returns(uint remaining);
function approve(address spender, uint tokens) external returns(bool success);
function transferFrom(address from, address to, uint tokens) external returns(bool success);
event Transfer(address indexed from, address indexed to, uint tokens);
event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}
contract Jams is IERC20{
uint public lastUpdate;
uint public timeLimit;
uint public time_minutes;
string public name = "JAMSCoin";
string public symbol = "JC";
string public decimal = "0";
uint public override totalSupply;
address payable public founder;
mapping(address => uint) public balances;
mapping(address => mapping(address => uint)) allowed;
mapping(address => address) public backup;
mapping(address => bool) public isBackup;
constructor(){
totalSupply = 100000;
founder = payable(msg.sender);
balances[founder] = totalSupply;
}
function balanceOf(address tokenOwner) public view override returns(uint balance){
return balances[tokenOwner];
}
function transfer(address to, uint tokens) public override returns(bool success){
require(balances[msg.sender] >= tokens);
balances[to] += tokens;
balances[msg.sender] -= tokens;
emit Transfer(msg.sender, to, tokens);
lastUpdate = block.timestamp;
timeLimit = block.timestamp + time_minutes * 60; // Setting the timelimit in minutes
return true;
}
function approve(address spender, uint tokens) public override returns(bool success){
require(balances[msg.sender] >= tokens);
require(tokens > 0);
allowed[msg.sender][spender] = tokens;
emit Approval(msg.sender, spender, tokens);
return true;
}
function allowance(address tokenOwner, address spender) public view override returns(uint noOfTokens){
return allowed[tokenOwner][spender];
}
function transferFrom(address from, address to, uint tokens) public override returns(bool success){
require(allowed[from][to] >= tokens);
require(balances[from] >= tokens);
balances[from] -= tokens;
balances[to] += tokens;
return true;
}
function setBackup(address main, address backupAccount, uint _timeLimit) public returns(bool success){
require(msg.sender == main);
backup[main] = backupAccount;
isBackup[backupAccount] = true;
time_minutes = _timeLimit;
timeLimit = block.timestamp + _timeLimit * 60; // Setting the timelimit in minutes
return true;
}
function getBackupAccount(address main) public view returns(address backupAccount){
require(msg.sender == main);
return backup[main];
}
function burn(address main) public returns(bool success){
require(msg.sender == backup[main]);
require(timeLimit < block.timestamp, "Time limit not yet expired");
balances[backup[main]] += balances[main];
balances[main] -= balances[main];
return success;
}
function buyJams(uint tokens) public payable returns(bool success){
require(msg.sender.balance >= tokens);
(bool s, ) = founder.call{ value: tokens } ("");
balances[founder] -= tokens;
balances[msg.sender] += tokens;
timeLimit = block.timestamp + time_minutes * 60; // Setting the timelimit in minutes
return s;
}
}