vesting stake redemption

This commit is contained in:
gozzy 2023-03-15 16:35:14 +00:00
parent eb35892b1c
commit 6e9bbaae8d
5 changed files with 27 additions and 15 deletions

View File

@ -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();

View File

@ -1,5 +1,3 @@
// SPDX-License-Identifier: Unlicense
pragma solidity 0.8.0;
interface IERC20 {

View File

@ -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);
}

View File

@ -0,0 +1,9 @@
pragma solidity 0.8.0;
interface IStaking {
function checkReward(address owner) external returns (uint256);
function getReward() external;
}

View File

@ -1,5 +1,3 @@
// SPDX-License-Identifier: Unlicense
pragma solidity >=0.6.2;
interface IUniswapV2Router02 {