vesting stake redemption
This commit is contained in:
parent
eb35892b1c
commit
6e9bbaae8d
@ -1,6 +1,7 @@
|
||||
pragma solidity 0.8.0;
|
||||
|
||||
import "./interfaces/IERC20.sol";
|
||||
import "./interfaces/IStaking.sol";
|
||||
import "./interfaces/IGovernance.sol";
|
||||
|
||||
contract DelegatedInstance {
|
||||
@ -18,6 +19,7 @@ contract DelegatedInstance {
|
||||
address tokenAddress,
|
||||
uint256 stakeAmount
|
||||
) {
|
||||
_stakingAddress = IGovernance(governanceAddress).Staking();
|
||||
_governanceAddress = governanceAddress;
|
||||
_tokenAddress = tokenAddress;
|
||||
|
||||
@ -48,13 +50,18 @@ contract DelegatedInstance {
|
||||
IGovernance(_governanceAddress).delegate(to);
|
||||
}
|
||||
|
||||
function unlockAndRedeem() public isSpender {
|
||||
function unlockAndRedeem() public {
|
||||
require(msg.sender == _sender, "INVALID SENDER");
|
||||
|
||||
uint256 reward = IStaking(_stakingAddress).checkReward();
|
||||
uint256 stake = _balance;
|
||||
|
||||
delete balance;
|
||||
delete _balance;
|
||||
|
||||
IGovernance(_governanceAddress).unlock(stake);
|
||||
IERC20(_tokenAddress).transfer(_spender, stake);
|
||||
IStaking(_stakingAddress).getReward();
|
||||
|
||||
IERC20(_tokenAddress).transfer(_spender, stake + reward);
|
||||
}
|
||||
|
||||
}
|
||||
@ -66,7 +73,7 @@ contract DelegatedVesting {
|
||||
address public _tokenAddress;
|
||||
|
||||
mapping(address => uint256) _balances;
|
||||
mapping(address => address) _instance;
|
||||
mapping(address => address) _instances;
|
||||
mapping(address => uint256) _commitments;
|
||||
|
||||
constructor(
|
||||
@ -85,7 +92,7 @@ contract DelegatedVesting {
|
||||
}
|
||||
|
||||
function isDelegatedCommitment(address stakeholder) public view returns (bool) {
|
||||
return isActiveCommitment(stakeholder) && _instance[stakeholder] != address(0x0);
|
||||
return isActiveCommitment(stakeholder) && _instances[stakeholder] != address(0x0);
|
||||
}
|
||||
|
||||
function isFulfilledCommitment(address stakeholder) public view returns (bool) {
|
||||
@ -120,7 +127,7 @@ contract DelegatedVesting {
|
||||
v, r, s
|
||||
);
|
||||
|
||||
_instance[msg.sender] = address(e);
|
||||
_instances[msg.sender] = address(e);
|
||||
|
||||
IERC20(_tokenAddress).approve(address(e), _balances[msg.sender]);
|
||||
e.lockAndDelegate(delegateAddress, _balances[msg.sender], deadline, v, r, s);
|
||||
@ -131,10 +138,10 @@ contract DelegatedVesting {
|
||||
require(isFulfilledCommitment(msg.sender), "INVALID FULFILLMENT");
|
||||
|
||||
uint256 stake = _balances[msg.sender];
|
||||
address delegated = _instance[msg.sender];
|
||||
address delegated = _instances[msg.sender];
|
||||
|
||||
delete _balances[msg.sender];
|
||||
delete _instance[msg.sender];
|
||||
delete _instances[msg.sender];
|
||||
|
||||
if(delegated != address(0x0)){
|
||||
DelegatedInstance(delegated).unlockAndRedeem();
|
||||
|
@ -1,5 +1,3 @@
|
||||
// SPDX-License-Identifier: Unlicense
|
||||
|
||||
pragma solidity 0.8.0;
|
||||
|
||||
interface IERC20 {
|
||||
|
@ -1,5 +1,3 @@
|
||||
// SPDX-License-Identifier: Unlicense
|
||||
|
||||
pragma solidity 0.8.0;
|
||||
|
||||
interface IGovernance {
|
||||
@ -17,6 +15,8 @@ interface IGovernance {
|
||||
|
||||
function undelegate() external;
|
||||
|
||||
function unlock(address to) external;
|
||||
function unlock(uint256 amount) external;
|
||||
|
||||
function Staking() external returns (address);
|
||||
|
||||
}
|
||||
|
9
src/interfaces/IStaking.sol
Normal file
9
src/interfaces/IStaking.sol
Normal file
@ -0,0 +1,9 @@
|
||||
pragma solidity 0.8.0;
|
||||
|
||||
interface IStaking {
|
||||
|
||||
function checkReward(address owner) external returns (uint256);
|
||||
|
||||
function getReward() external;
|
||||
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
// SPDX-License-Identifier: Unlicense
|
||||
|
||||
pragma solidity >=0.6.2;
|
||||
|
||||
interface IUniswapV2Router02 {
|
||||
|
Loading…
Reference in New Issue
Block a user