mirror of https://github.com/logos-co/staking.git
rename variables
This commit is contained in:
parent
6a79af5f95
commit
c2142c1306
|
@ -15,10 +15,10 @@ contract StakeManager is ERC20 {
|
||||||
mapping (address => Account) accounts;
|
mapping (address => Account) accounts;
|
||||||
|
|
||||||
struct Account {
|
struct Account {
|
||||||
uint256 lockTime;
|
uint256 lockUntil;
|
||||||
uint256 balance;
|
uint256 balance;
|
||||||
uint256 multiplier;
|
uint256 multiplier;
|
||||||
uint256 update;
|
uint256 lastAccured;
|
||||||
uint256 epoch;
|
uint256 epoch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ contract StakeManager is ERC20 {
|
||||||
|
|
||||||
uint256 currentEpoch;
|
uint256 currentEpoch;
|
||||||
uint256 pendingReward;
|
uint256 pendingReward;
|
||||||
|
uint256 public totalSupply;
|
||||||
|
|
||||||
uint256 public constant EPOCH_SIZE = 1 week;
|
uint256 public constant EPOCH_SIZE = 1 week;
|
||||||
|
|
||||||
|
@ -43,27 +44,34 @@ contract StakeManager is ERC20 {
|
||||||
|
|
||||||
function increaseBalance(uint256 _amount, uint256 _time) external {
|
function increaseBalance(uint256 _amount, uint256 _time) external {
|
||||||
Account storage account = accounts[msg.sender];
|
Account storage account = accounts[msg.sender];
|
||||||
|
uint256 inceasedMultiplier = _amount * (_time + 1);
|
||||||
account.balance += _amount;
|
account.balance += _amount;
|
||||||
uint256 mp = calcInitialMultiplierPoints(_amount, _time);
|
|
||||||
account.multiplier += mp;
|
account.multiplier += mp;
|
||||||
multiplierSupply += mp;
|
account.lastAccured = now();
|
||||||
account.update = now();
|
account.lockUntil = now() + _time;
|
||||||
account.lockTime = now() + _time;
|
|
||||||
mint(msg.sender, _amount);
|
multiplierSupply += inceasedMultiplier;
|
||||||
|
totalSupply += _amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function decreaseBalance(uint256 _amount) external {
|
function decreaseBalance(uint256 _amount) external {
|
||||||
Account storage account = accounts[msg.sender];
|
Account storage account = accounts[msg.sender];
|
||||||
|
uint256 reducedMultiplier = (_amount * account.multiplier) / account.balance;
|
||||||
|
account.multiplier -= reducedMultiplier;
|
||||||
account.balance -= _amount;
|
account.balance -= _amount;
|
||||||
account.multiplier -= calcInitialMultiplierPoints(_amount, 1);
|
|
||||||
burn(msg.sender, _amount);
|
multiplierSupply -= reducedMultiplier;
|
||||||
|
totalSupply -= _amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function balanceLock(uint256 _time) external {
|
function balanceLock(uint256 _time) external {
|
||||||
Account storage account = accounts[msg.sender];
|
Account storage account = accounts[msg.sender];
|
||||||
require(now() + _time > account.lockTime, "Cannot decrease lock time");
|
require(now() + _time > account.lockUntil, "Cannot decrease lock time");
|
||||||
account.lockTime = now() + _time;
|
uint256 dT = now() + _time - account.lockUntil;
|
||||||
|
account.lockUntil = now() + _time;
|
||||||
|
account.multiplier += _amount * dT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,11 +80,11 @@ contract StakeManager is ERC20 {
|
||||||
*/
|
*/
|
||||||
function mintMultiplierPoints(address _vault) external {
|
function mintMultiplierPoints(address _vault) external {
|
||||||
Account storage account = accounts[msg.sender];
|
Account storage account = accounts[msg.sender];
|
||||||
uint256 dT = now() - account.update;
|
uint256 dT = now() - account.lastAccured;
|
||||||
account.update = now();
|
uint256 inceasedMultiplier = calcAccuredMultiplierPoints(account.balance, account.multiplier, dT);
|
||||||
uint256 mp = calcAccuredMultiplierPoints(account.balance, account.multiplier, dT);
|
account.lastAccured = now();
|
||||||
multiplierSupply += mp;
|
account.multiplier += inceasedMultiplier;
|
||||||
account.multiplier += mp;
|
multiplierSupply += inceasedMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeEpochReward() external {
|
function executeEpochReward() external {
|
||||||
|
@ -107,10 +115,6 @@ contract StakeManager is ERC20 {
|
||||||
stakedToken.transfer(_vault, userReward);
|
stakedToken.transfer(_vault, userReward);
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcInitialMultiplierPoints(uint256 _amount, uint256 _time) pure public returns(uint256) {
|
|
||||||
return _amount * (_time + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function calcAccuredMultiplierPoints(uint256 _balance, uint256 _currentMp, uint256 _deltaTime) pure public returns(uint256) {
|
function calcAccuredMultiplierPoints(uint256 _balance, uint256 _currentMp, uint256 _deltaTime) pure public returns(uint256) {
|
||||||
uint256 accured = _balance * (MP_APY * _deltaTime);
|
uint256 accured = _balance * (MP_APY * _deltaTime);
|
||||||
uint256 newMp = accured + _currentMp;
|
uint256 newMp = accured + _currentMp;
|
||||||
|
|
Loading…
Reference in New Issue