Skip to content

Commit

Permalink
Merge pull request #93 from lista-dao/240923_helio_provider_pool_switch
Browse files Browse the repository at this point in the history
! change helio provider withdraw pool to stake manager
  • Loading branch information
qingyang-lista authored Sep 25, 2024
2 parents 2c369f3 + e27c26e commit d1ccbd9
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 21 deletions.
5 changes: 4 additions & 1 deletion contracts/ceros/interfaces/IBNBStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ interface IBNBStakingPool {
function getMinUnstake() external view returns (uint256);

function getPendingUnstakesOf(address claimer) external view returns (uint256);
}

// ListaStakeManager, minimum amount of BNB required for a withdrawal
function minBnb() external view returns (uint256);
}
1 change: 1 addition & 0 deletions contracts/ceros/interfaces/IDao.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ interface IDao {

function collaterals(address token) external view returns (GemJoinLike, bytes32, uint32, address);

function locked(address token, address usr) external view returns (uint256);
}
4 changes: 2 additions & 2 deletions contracts/ceros/interfaces/IHelioProviderV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface IHelioProviderV2 {

event ChangeMasterVault(address masterVault);

event ChangeBNBStakingPool(address pool);
event ChangeBNBStakingPool(address pool, bool useStakeManagerPool);

event ChangeLiquidationStrategy(address strategy);

Expand All @@ -54,7 +54,7 @@ interface IHelioProviderV2 {
// in BNB
function provide() external payable returns (uint256);
function provide(address _delegateTo) external payable returns (uint256);
function changeDelegatee(address _delegateTo) external;
function delegateAllTo(address _newDelegateTo) external;

// in aBNBc
// function provideInABNBc(uint256 amount) external returns (uint256);
Expand Down
4 changes: 4 additions & 0 deletions contracts/ceros/mocks/Dao.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ contract Dao is IDao {

function collaterals(address token) external view returns (GemJoinLike gem, bytes32 ilk, uint32 live, address clip) {}

function locked(address token, address usr) public view returns (uint256) {
return 0;
}

}
63 changes: 45 additions & 18 deletions contracts/ceros/upgrades/HelioProviderV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ ReentrancyGuardUpgradeable
// a multi-sig wallet which can pause the contract in case of emergency
address public _guardian;

// added on 2021-09-23
bool public _useStakeManagerPool;

/**
* Modifiers
*/
Expand Down Expand Up @@ -118,28 +121,45 @@ ReentrancyGuardUpgradeable
}

/**
* CHANGE DELEGATEE
* @notice By burning all the collateral tokens from the
* old delegatee and minting the same amount to the new delegatee,
* also replace delegateTo address by the new one to perform the change.
* @notice Delegate all clisBNB to a new delegatee or self
new delegatee can be self or anyone else, but not zero address
* @param _newDelegateTo address of the new delegatee
*/
function changeDelegatee(address _newDelegateTo) external override whenNotPaused {
function delegateAllTo(address _newDelegateTo) external override whenNotPaused {
require(_newDelegateTo != address(0), "delegateTo cannot be zero address");
require(
_delegation[msg.sender].amount > 0 && _delegation[msg.sender].delegateTo != _newDelegateTo,
"delegatee must differ from the current one"
);
// get user total deposit
uint256 totalLocked = _dao.locked(_ceToken, msg.sender);

Delegation storage delegation = _delegation[msg.sender];
address oldDelegateTo = delegation.delegateTo;
// burn old delegatee's token
_collateralToken.burn(oldDelegateTo, delegation.amount);
// mint to new delegatee
_collateralToken.mint(_newDelegateTo, delegation.amount);
// change delegation info
delegation.delegateTo = _newDelegateTo;

// Step 1. burn all tokens
if (delegation.amount > 0) {
// burn delegatee's token
_collateralToken.burn(oldDelegateTo, delegation.amount);
// burn self's token
_collateralToken.burn(msg.sender, totalLocked - delegation.amount);
} else {
_collateralToken.burn(msg.sender, totalLocked);
}

// Step 2. save new delegatee and mint all tokens to delegatee
if (_newDelegateTo == msg.sender) {
// mint all to self
_collateralToken.mint(msg.sender, totalLocked);
// remove delegatee
delete _delegation[msg.sender];
} else {
// mint all to new delegatee
_collateralToken.mint(_newDelegateTo, totalLocked);
// save delegatee's info
delegation.delegateTo = _newDelegateTo;
delegation.amount = totalLocked;
}

emit ChangeDelegateTo(msg.sender, oldDelegateTo, _newDelegateTo);
}

/**
* RELEASE
*/
Expand All @@ -152,7 +172,13 @@ ReentrancyGuardUpgradeable
returns (uint256 realAmount)
{
require(recipient != address(0));
uint256 minumumUnstake = _pool.getMinUnstake();
uint256 minumumUnstake = 0;
if (_useStakeManagerPool) {
minumumUnstake = _pool.minBnb();
} else {
minumumUnstake = _pool.getMinUnstake();
}

require(
amount >= minumumUnstake,
"value must be greater than min unstake amount"
Expand Down Expand Up @@ -292,9 +318,10 @@ ReentrancyGuardUpgradeable
_masterVault = IMasterVault(masterVault);
emit ChangeMasterVault(masterVault);
}
function changeBNBStakingPool(address pool) external onlyOwner {
function changeBNBStakingPool(address pool, bool useStakeManagerPool) external onlyOwner {
_pool = IBNBStakingPool(pool);
emit ChangeBNBStakingPool(pool);
_useStakeManagerPool = useStakeManagerPool;
emit ChangeBNBStakingPool(pool, useStakeManagerPool);
}
function changeLiquidationStrategy(address strategy) external onlyOwner {
_liquidationStrategy = strategy;
Expand Down

0 comments on commit d1ccbd9

Please sign in to comment.