-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContract.sol
More file actions
61 lines (54 loc) · 2.15 KB
/
Contract.sol
File metadata and controls
61 lines (54 loc) · 2.15 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;
contract Interval {
string public name = "Interval";
string public symbol = "INT";
uint8 public decimals = 18;
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
constructor() {
uint256 initialSupply = 200000000 * 10 ** uint256(decimals);
balanceOf[msg.sender] = initialSupply;
totalSupply = initialSupply;
emit Transfer(address(0), msg.sender, initialSupply);
}
function transfer(address to, uint256 value) public returns (bool success) {
require(to != address(0), "transfer to zero address");
require(balanceOf[msg.sender] >= value, "insufficient balance");
unchecked {
balanceOf[msg.sender] -= value;
balanceOf[to] += value;
}
emit Transfer(msg.sender, to, value);
return true;
}
function approve(address spender, uint256 value) public returns (bool success) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) public returns (bool success) {
require(to != address(0), "transfer to zero address");
require(balanceOf[from] >= value, "insufficient balance");
require(allowance[from][msg.sender] >= value, "allowance too low");
unchecked {
balanceOf[from] -= value;
balanceOf[to] += value;
allowance[from][msg.sender] -= value;
}
emit Transfer(from, to, value);
return true;
}
function burn(uint256 value) public returns (bool success) {
require(balanceOf[msg.sender] >= value, "insufficient balance");
unchecked {
balanceOf[msg.sender] -= value;
totalSupply -= value;
}
emit Transfer(msg.sender, address(0), value);
return true;
}
}