Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native link withdrawals #116

Closed
wants to merge 16 commits into from
Closed
166 changes: 110 additions & 56 deletions contracts/core/StakingPool.sol

Large diffs are not rendered by default.

51 changes: 30 additions & 21 deletions contracts/core/base/StakingRewardsPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,35 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
mapping(address => uint256) private shares;
uint256 public totalShares;

/**
* @notice Initializes the contract
* @param _token address of asset token
* @param _liquidTokenName name of liquid staking token
* @param _liquidTokenSymbol symbol of liquid staking token
*/
function __StakingRewardsPool_init(
address _token,
string memory _derivativeTokenName,
string memory _derivativeTokenSymbol
string memory _liquidTokenName,
string memory _liquidTokenSymbol
) public onlyInitializing {
__ERC677_init(_derivativeTokenName, _derivativeTokenSymbol, 0);
__ERC677_init(_liquidTokenName, _liquidTokenSymbol, 0);
__UUPSUpgradeable_init();
__Ownable_init();
token = IERC20Upgradeable(_token);
}

/**
* @notice returns the total supply of staking derivative tokens
* @notice Returns the total supply of liquid staking tokens
* @return total supply
*/
function totalSupply() public view override returns (uint256) {
return _totalStaked();
}

/**
* @notice returns an account's stake balance
* @notice Returns an account's LST balance
* @param _account account address
* @return account's stake balance
* @return account's balance
*/
function balanceOf(address _account) public view override returns (uint256) {
uint256 balance = getStakeByShares(shares[_account]);
Expand All @@ -53,7 +59,7 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice returns an account's share balance
* @notice Returns an account's share balance
* @param _account account address
* @return account's share balance
*/
Expand All @@ -62,7 +68,7 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice returns the amount of shares that corresponds to a staked amount
* @notice Returns the amount of shares that corresponds to an LST amount
* @param _amount staked amount
* @return amount of shares
*/
Expand All @@ -76,9 +82,9 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice returns the amount of stake that corresponds to an amount of shares
* @notice Returns the amount of LST that corresponds to an amount of shares
* @param _amount shares amount
* @return amount of stake
* @return amount of LST
*/
function getStakeByShares(uint256 _amount) public view returns (uint256) {
if (totalShares == 0) {
Expand All @@ -89,7 +95,7 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice transfers shares from one account to another
* @notice Transfers shares from sender to another account
* @param _recipient account to transfer to
* @param _sharesAmount amount of shares to transfer
*/
Expand All @@ -99,7 +105,7 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice transfers shares from one account to another
* @notice Transfers shares from one account to another
* @param _sender account to transfer from
* @param _recipient account to transfer to
* @param _sharesAmount amount of shares to transfer
Expand All @@ -116,13 +122,13 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice returns the total amount of assets staked in the pool
* @notice Returns the total amount of asset tokens staked in the pool
* @return total staked amount
*/
function _totalStaked() internal view virtual returns (uint256);

/**
* @notice transfers a stake balance from one account to another
* @notice Transfers an LST balance from one account to another
* @param _sender account to transfer from
* @param _recipient account to transfer to
* @param _amount amount to transfer
Expand All @@ -145,7 +151,7 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice transfers shares from one account to another
* @notice Transfers shares from one account to another
* @param _sender account to transfer from
* @param _recipient account to transfer to
* @param _sharesAmount amount of shares to transfer
Expand All @@ -166,8 +172,8 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice mints new shares to an account
* @dev takes a stake amount and calculates the amount of shares it corresponds to
* @notice Mints new shares to an account
* @dev takes an LST amount and calculates the amount of shares it corresponds to
* @param _recipient account to mint shares for
* @param _amount stake amount
*/
Expand All @@ -179,7 +185,7 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice mints new shares to an account
* @notice Mints new shares to an account
* @param _recipient account to mint shares for
* @param _amount shares amount
*/
Expand All @@ -197,10 +203,10 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
}

/**
* @notice burns shares belonging to an account
* @dev takes a stake amount and calculates the amount of shares it corresponds to
* @notice Burns shares belonging to an account
* @dev takes an LST amount and calculates the amount of shares it corresponds to
* @param _account account to burn shares for
* @param _amount stake amount
* @param _amount LST amount
*/
function _burn(address _account, uint256 _amount) internal override {
uint256 sharesToBurn = getSharesByStake(_amount);
Expand All @@ -214,5 +220,8 @@ abstract contract StakingRewardsPool is ERC677Upgradeable, UUPSUpgradeable, Owna
emit Transfer(_account, address(0), _amount);
}

/**
* @dev Checks authorization for contract upgrades
*/
function _authorizeUpgrade(address) internal override onlyOwner {}
}
8 changes: 8 additions & 0 deletions contracts/core/interfaces/IPriorityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ interface IPriorityPool {

function poolStatus() external view returns (PoolStatus);

function canWithdraw(address _account, uint256 _distributionAmount) external view returns (uint256);

function pauseForUpdate() external;

function setPoolStatus(PoolStatus _status) external;
Expand All @@ -24,4 +26,10 @@ interface IPriorityPool {
uint256 _amountDistributed,
uint256 _sharesAmountDistributed
) external;

function executeQueuedWithdrawals(uint256 _amount, bytes[] calldata _data) external;

function checkUpkeep(bytes calldata) external view returns (bool, bytes memory);

function performUpkeep(bytes calldata _performData) external;
}
21 changes: 17 additions & 4 deletions contracts/core/interfaces/IStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@ pragma solidity 0.8.15;
import "./IStakingRewardsPool.sol";

interface IStakingPool is IStakingRewardsPool {
function deposit(address _account, uint256 _amount) external;
function deposit(
address _account,
uint256 _amount,
bytes[] calldata _data
) external;

function withdraw(
address _account,
address _receiver,
uint256 _amount
uint256 _amount,
bytes[] calldata _data
) external;

function strategyDeposit(uint256 _index, uint256 _amount) external;
function strategyDeposit(
uint256 _index,
uint256 _amount,
bytes calldata _data
) external;

function strategyWithdraw(uint256 _index, uint256 _amount) external;
function strategyWithdraw(
uint256 _index,
uint256 _amount,
bytes calldata _data
) external;

function updateStrategyRewards(uint256[] memory _strategyIdxs, bytes memory _data) external;

Expand Down
4 changes: 2 additions & 2 deletions contracts/core/interfaces/IStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity 0.8.15;

interface IStrategy {
function deposit(uint256 _amount) external;
function deposit(uint256 _amount, bytes calldata _data) external;

function withdraw(uint256 _amount) external;
function withdraw(uint256 _amount, bytes calldata _data) external;

function updateDeposits(bytes calldata _data)
external
Expand Down
10 changes: 10 additions & 0 deletions contracts/core/interfaces/IWithdrawalPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;

interface IWithdrawalPool {
function getTotalQueuedWithdrawals() external view returns (uint256);

function deposit(uint256 _amount) external;

function queueWithdrawal(address _account, uint256 _amount) external;
}
Loading
Loading