mirror of
https://github.com/logos-co/staking.git
synced 2025-01-11 03:06:24 +00:00
fix balance lock
This commit is contained in:
parent
c2142c1306
commit
1375440bd5
@ -39,18 +39,17 @@ contract StakeManager is ERC20 {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
epoch[0].startTime = now();
|
epoch[0].startTime = now();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
uint256 increasedMultiplier = _amount * (_time + 1);
|
||||||
account.balance += _amount;
|
account.balance += _amount;
|
||||||
account.multiplier += mp;
|
account.multiplier += mp;
|
||||||
account.lastAccured = now();
|
account.lastAccured = now();
|
||||||
account.lockUntil = now() + _time;
|
account.lockUntil = now() + _time;
|
||||||
|
|
||||||
multiplierSupply += inceasedMultiplier;
|
multiplierSupply += increasedMultiplier;
|
||||||
totalSupply += _amount;
|
totalSupply += _amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,13 +64,21 @@ contract StakeManager is ERC20 {
|
|||||||
totalSupply -= _amount;
|
totalSupply -= _amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locks entire balance for more amount of time.
|
||||||
|
* @param _time amount of time to lock from now.
|
||||||
|
*/
|
||||||
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.lockUntil, "Cannot decrease lock time");
|
require(now() + _time > account.lockUntil, "Cannot decrease lock time");
|
||||||
uint256 dT = now() + _time - account.lockUntil;
|
|
||||||
|
//if balance still locked, multipliers must be minted from difference of time.
|
||||||
|
uint256 dT = account.lockUntil > now() ? now() + _time - account.lockUntil : _time);
|
||||||
account.lockUntil = now() + _time;
|
account.lockUntil = now() + _time;
|
||||||
account.multiplier += _amount * dT;
|
uint256 increasedMultiplier = _amount * dT;
|
||||||
|
|
||||||
|
account.multiplier += increasedMultiplier;
|
||||||
|
multiplierSupply += increasedMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,11 +87,13 @@ 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.lastAccured;
|
uint256 lastCall = now() - account.lastAccured;
|
||||||
uint256 inceasedMultiplier = calcAccuredMultiplierPoints(account.balance, account.multiplier, dT);
|
uint256 increasedMultiplier = checkMaxMultiplier(
|
||||||
|
account.balance * (MP_APY * lastCall),
|
||||||
|
account.multiplier);
|
||||||
account.lastAccured = now();
|
account.lastAccured = now();
|
||||||
account.multiplier += inceasedMultiplier;
|
account.multiplier += increasedMultiplier;
|
||||||
multiplierSupply += inceasedMultiplier;
|
multiplierSupply += increasedMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeEpochReward() external {
|
function executeEpochReward() external {
|
||||||
@ -115,10 +124,9 @@ contract StakeManager is ERC20 {
|
|||||||
stakedToken.transfer(_vault, userReward);
|
stakedToken.transfer(_vault, userReward);
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcAccuredMultiplierPoints(uint256 _balance, uint256 _currentMp, uint256 _deltaTime) pure public returns(uint256) {
|
function checkMaxMultiplier(uint256 _increasedMultiplier, uint256 _currentMp) private view returns(uint256 _maxToIncrease) {
|
||||||
uint256 accured = _balance * (MP_APY * _deltaTime);
|
uint256 newMp = _increasedMultiplier + _currentMp;
|
||||||
uint256 newMp = accured + _currentMp;
|
return newMp > MAX_MP ? MAX_MP - newMp : _increasedMultiplier;
|
||||||
return newMp > MAX_MP ? MAX_MP - newMp : accurred;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user