-
Notifications
You must be signed in to change notification settings - Fork 100
/
ERC20-rebase.sol
60 lines (49 loc) · 1.79 KB
/
ERC20-rebase.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
pragma solidity ^0.8.0;
import "forge-std/interfaces/IERC20.sol";
import {ERC20Base} from "./base/ERC20Base.sol";
import "forge-std/Test.sol";
contract ERC20Rebase is ERC20Base, Test {
uint256 public lastRebaseTimestamp;
uint256 public rebaseInterval = 1 minutes;
uint256 public rebaseAmt = 5;
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals,
uint256 _initialSupply,
uint256 _rebaseInterval,
uint256 _rebaseAmt
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
totalSupply = _initialSupply;
balanceOf[msg.sender] = _initialSupply;
lastRebaseTimestamp = block.timestamp;
rebaseInterval = _rebaseInterval;
rebaseAmt = _rebaseAmt;
emit Transfer(address(0), msg.sender, _initialSupply);
}
function setRebaseAmount(uint256 _rebaseAmt) public {
rebaseAmt = _rebaseAmt;
}
function setRebaseInterval(uint256 _rebaseInterval) public {
rebaseInterval = _rebaseInterval;
}
modifier rebase() {
uint256 timeSinceLastRebase = block.timestamp - lastRebaseTimestamp;
if (timeSinceLastRebase >= rebaseInterval) {
uint256 rebaseMultiplier = timeSinceLastRebase / rebaseInterval;
totalSupply += rebaseAmt * rebaseMultiplier;
balanceOf[msg.sender] += rebaseAmt * rebaseMultiplier;
lastRebaseTimestamp += rebaseInterval * rebaseMultiplier;
}
_;
}
function transfer(address to, uint256 amount) public override rebase returns (bool) {
super.transfer(to, amount);
}
function transferFrom(address from, address to, uint256 amount) public override rebase returns (bool) {
super.transferFrom(from, to, amount);
}
}