mirror of https://github.com/logos-co/staking.git
simplfy contract
This commit is contained in:
parent
254afe9932
commit
e9d71449c1
|
@ -1,49 +1,77 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
pragma solidity 0.6.12;
|
pragma solidity 0.8.19;
|
||||||
|
|
||||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||||
|
|
||||||
contract StakeManager is ERC20 {
|
contract StakeManager is ERC20 {
|
||||||
|
|
||||||
address stakedToken;
|
ERC20 stakedToken;
|
||||||
|
|
||||||
bytes32 vaultCodehash;
|
uint256 public constant MP_APY = 1;
|
||||||
uint256 mp_supply = 0;
|
|
||||||
uint256 public constant MP_APY = 1;
|
|
||||||
uint256 public constant STAKE_APY = 1;
|
uint256 public constant STAKE_APY = 1;
|
||||||
uint256 public constant MAX_BOOST = 1;
|
uint256 public constant MAX_BOOST = 1;
|
||||||
|
uint256 public constant MAX_MP = 1;
|
||||||
|
mapping (address => Account) accounts;
|
||||||
|
|
||||||
|
struct Account {
|
||||||
|
uint256 lockTime;
|
||||||
|
uint256 balance;
|
||||||
|
uint256 multiplier;
|
||||||
|
uint256 multiplierUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
mapping (address => Account) account;
|
mapping (address => Account) account;
|
||||||
|
|
||||||
|
|
||||||
modifier onlyVault {
|
function increaseBalance(uint256 _amount, uint256 _time) external {
|
||||||
require(msg.sender.codehash() == vaultCodehash, "Unauthorized Codehash");
|
accounts[msg.sender].balance += _amount;
|
||||||
|
uint256 mp = calcInitialMultiplierPoints(_amount, _time);
|
||||||
|
accounts[msg.sender].multiplier += mp;
|
||||||
|
multiplierSupply += mp;
|
||||||
|
accounts[msg.sender].update = now();
|
||||||
|
accounts[msg.sender].lockTime = now() + _time;
|
||||||
|
mint(msg.sender, _amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function join(uint256 amount) external onlyVault {
|
function decreaseBalance(uint256 _amount) external {
|
||||||
|
accounts[msg.sender].balance -= _amount;
|
||||||
|
accounts[msg.sender].multiplier -= calcInitialMultiplierPoints(_amount, 1);
|
||||||
|
burn(msg.sender, _amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function lock(uint256 amount, uint256 time) external onlyVault {
|
|
||||||
|
function balanceLock(uint256 _time) external {
|
||||||
|
require(now() + _time > accounts[msg.sender].lockTime, "Cannot decrease lock time");
|
||||||
|
accounts[msg.sender].lockTime = now() + _time;
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinAndLock(uint256 amount, uint256 time) external onlyVault {
|
/**
|
||||||
|
* @dev Function called to increase the Multiplier Points of a Vault
|
||||||
|
* @param _vault
|
||||||
|
*/
|
||||||
|
function mintMultiplierPoints(address _vault) external {
|
||||||
|
uint256 dT = now() - accounts[msg.sender].update;
|
||||||
|
accounts[msg.sender].update = now();
|
||||||
|
uint256 mp = calcAccuredMultiplierPoints(accounts[_vault].balance, accounts[_vault].multiplier, dT);
|
||||||
|
multiplierSupply += mp;
|
||||||
|
accounts[_vault].multiplier += mp;
|
||||||
}
|
}
|
||||||
|
|
||||||
function leave(uint256 amount) external {
|
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) {
|
||||||
|
uint256 accured = _balance * (MP_APY * _deltaTime);
|
||||||
|
uint256 newMp = accured + _currentMp;
|
||||||
|
return newMp > MAX_MP ? MAX_MP - newMp : accurred;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function getRewardsEmissions() public view returns(uint256){
|
function getRewardsEmissions() public view returns(uint256){
|
||||||
|
uint256 totalStaked = this.totalSupply;
|
||||||
}
|
uint256 share = this.multiplierSupply +totalSupply;
|
||||||
|
|
||||||
|
|
||||||
function increase_mp(uint256 amount) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue