Skip to content

Commit

Permalink
fixed prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
BkChoy committed Jul 16, 2024
1 parent bb139db commit aa0efea
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 65 deletions.
3 changes: 2 additions & 1 deletion contracts/core/StakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ contract StakingPool is StakingRewardsPool {
}

uint256 endingBalance = token.balanceOf(address(this));
if (endingBalance > startingBalance && endingBalance > unusedDepositLimit) revert InvalidDeposit();
if (endingBalance > startingBalance && endingBalance > unusedDepositLimit)
revert InvalidDeposit();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion contracts/core/interfaces/IPriorityPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ interface IPriorityPool {

function poolStatus() external view returns (PoolStatus);

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

function pauseForUpdate() external;

Expand Down
45 changes: 33 additions & 12 deletions contracts/core/priorityPool/WithdrawalPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ contract WithdrawalPool is UUPSUpgradeable, OwnableUpgradeable {
* @param _withdrawalIds list of withdrawal ids
* @return list of withdrawals corresponding to withdrawal ids
*/
function getWithdrawals(uint256[] calldata _withdrawalIds) external view returns (Withdrawal[] memory) {
function getWithdrawals(
uint256[] calldata _withdrawalIds
) external view returns (Withdrawal[] memory) {
Withdrawal[] memory withdrawals = new Withdrawal[](_withdrawalIds.length);

for (uint256 i = 0; i < _withdrawalIds.length; ++i) {
Expand Down Expand Up @@ -144,7 +146,9 @@ contract WithdrawalPool is UUPSUpgradeable, OwnableUpgradeable {
* @return list of withdrawal ids
*/
function getWithdrawalIdsByOwner(address _account) public view returns (uint256[] memory) {
uint256[] memory activeWithdrawals = new uint256[](queuedWithdrawalsByAccount[_account].length);
uint256[] memory activeWithdrawals = new uint256[](
queuedWithdrawalsByAccount[_account].length
);
uint256 totalActiveWithdrawals;

for (uint256 i = 0; i < activeWithdrawals.length; ++i) {
Expand Down Expand Up @@ -174,7 +178,9 @@ contract WithdrawalPool is UUPSUpgradeable, OwnableUpgradeable {
* @return list of withdrawal ids
* @return total withdrawable across all account's withdrawals
*/
function getFinalizedWithdrawalIdsByOwner(address _account) external view returns (uint256[] memory, uint256) {
function getFinalizedWithdrawalIdsByOwner(
address _account
) external view returns (uint256[] memory, uint256) {
uint256[] memory withdrawalIds = getWithdrawalIdsByOwner(_account);
uint256[] memory batchIds = getBatchIds(withdrawalIds);

Expand All @@ -191,7 +197,8 @@ contract WithdrawalPool is UUPSUpgradeable, OwnableUpgradeable {

if (batchIds[i] != 0) {
totalWithdrawable +=
(uint256(withdrawalBatches[batchIds[i]].stakePerShares) * uint256(withdrawal.sharesRemaining)) /
(uint256(withdrawalBatches[batchIds[i]].stakePerShares) *
uint256(withdrawal.sharesRemaining)) /
1e18;
}
} else {
Expand Down Expand Up @@ -229,10 +236,14 @@ contract WithdrawalPool is UUPSUpgradeable, OwnableUpgradeable {
WithdrawalBatch memory batch = withdrawalBatches[batchId];

if (withdrawalOwners[withdrawalId] != owner) revert SenderNotAuthorized();
if (batchId != 0 && withdrawalId <= withdrawalBatches[batchId - 1].indexOfLastWithdrawal)
revert InvalidWithdrawalId();
if (batchId != 0 && withdrawalId > batch.indexOfLastWithdrawal && withdrawal.partiallyWithdrawableAmount == 0)
revert InvalidWithdrawalId();
if (
batchId != 0 && withdrawalId <= withdrawalBatches[batchId - 1].indexOfLastWithdrawal
) revert InvalidWithdrawalId();
if (
batchId != 0 &&
withdrawalId > batch.indexOfLastWithdrawal &&
withdrawal.partiallyWithdrawableAmount == 0
) revert InvalidWithdrawalId();

if (withdrawalId <= batch.indexOfLastWithdrawal) {
amountToWithdraw +=
Expand Down Expand Up @@ -288,7 +299,10 @@ contract WithdrawalPool is UUPSUpgradeable, OwnableUpgradeable {
* @return true if withdrawal should be executed, false otherwise
*/
function checkUpkeep(bytes calldata) external view returns (bool, bytes memory) {
if (_getStakeByShares(totalQueuedShareWithdrawals) != 0 && priorityPool.canWithdraw(address(this), 0) != 0) {
if (
_getStakeByShares(totalQueuedShareWithdrawals) != 0 &&
priorityPool.canWithdraw(address(this), 0) != 0
) {
return (true, "");
}
return (false, "");
Expand Down Expand Up @@ -340,13 +354,20 @@ contract WithdrawalPool is UUPSUpgradeable, OwnableUpgradeable {
if (sharesRemaining > sharesToWithdraw) {
queuedWithdrawals[i] = Withdrawal(
uint128(sharesRemaining - sharesToWithdraw),
uint128(queuedWithdrawals[i].partiallyWithdrawableAmount + _getStakeByShares(sharesToWithdraw))
uint128(
queuedWithdrawals[i].partiallyWithdrawableAmount +
_getStakeByShares(sharesToWithdraw)
)
);
indexOfNextWithdrawal = i;
withdrawalBatches.push(WithdrawalBatch(uint128(i - 1), uint128(_getStakeByShares(1 ether))));
withdrawalBatches.push(
WithdrawalBatch(uint128(i - 1), uint128(_getStakeByShares(1 ether)))
);
} else {
indexOfNextWithdrawal = i + 1;
withdrawalBatches.push(WithdrawalBatch(uint128(i), uint128(_getStakeByShares(1 ether))));
withdrawalBatches.push(
WithdrawalBatch(uint128(i), uint128(_getStakeByShares(1 ether)))
);
}

sharesToWithdraw = 0;
Expand Down
106 changes: 64 additions & 42 deletions contracts/linkStaking/FundFlowController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
uint256 toDeposit = 2 * _toDeposit;
bytes[] memory depositData = new bytes[](2);

(uint64[] memory opVaultDepositOrder, uint256 opVaultsTotalToDeposit) = _getVaultDepositOrder(
operatorVCS,
toDeposit
);
(
uint64[] memory opVaultDepositOrder,
uint256 opVaultsTotalToDeposit
) = _getVaultDepositOrder(operatorVCS, toDeposit);
depositData[0] = abi.encode(opVaultDepositOrder);

if (opVaultsTotalToDeposit < toDeposit) {
Expand All @@ -94,10 +94,10 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
uint256 toWithdraw = 2 * _toWithdraw;
bytes[] memory withdrawalData = new bytes[](2);

(uint64[] memory comVaultWithdrawalOrder, uint256 comVaultsTotalToWithdraw) = _getVaultWithdrawalOrder(
communityVCS,
toWithdraw
);
(
uint64[] memory comVaultWithdrawalOrder,
uint256 comVaultsTotalToWithdraw
) = _getVaultWithdrawalOrder(communityVCS, toWithdraw);
withdrawalData[1] = abi.encode(comVaultWithdrawalOrder);

if (comVaultsTotalToWithdraw < toWithdraw) {
Expand Down Expand Up @@ -138,7 +138,8 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {

if (
timeOfLastUpdateByGroup[nextUnbondedVaultGroup] != 0 &&
block.timestamp <= timeOfLastUpdateByGroup[curUnbondedVaultGroup] + unbondingPeriod + claimPeriod
block.timestamp <=
timeOfLastUpdateByGroup[curUnbondedVaultGroup] + unbondingPeriod + claimPeriod
) return (false, "");

if (
Expand All @@ -147,17 +148,18 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
block.timestamp <= timeOfLastUpdateByGroup[curUnbondedVaultGroup - 1] + claimPeriod
) return (false, "");

if (block.timestamp < timeOfLastUpdateByGroup[nextUnbondedVaultGroup] + unbondingPeriod) return (false, "");
if (block.timestamp < timeOfLastUpdateByGroup[nextUnbondedVaultGroup] + unbondingPeriod)
return (false, "");

(uint256[] memory curGroupOpVaultsToUnbond, uint256 nextGroupOpVaultsTotalUnbonded) = _getVaultUpdateData(
operatorVCS,
nextUnbondedVaultGroup
);
(
uint256[] memory curGroupOpVaultsToUnbond,
uint256 nextGroupOpVaultsTotalUnbonded
) = _getVaultUpdateData(operatorVCS, nextUnbondedVaultGroup);

(uint256[] memory curGroupComVaultsToUnbond, uint256 nextGroupComVaultsTotalUnbonded) = _getVaultUpdateData(
communityVCS,
nextUnbondedVaultGroup
);
(
uint256[] memory curGroupComVaultsToUnbond,
uint256 nextGroupComVaultsTotalUnbonded
) = _getVaultUpdateData(communityVCS, nextUnbondedVaultGroup);

return (
true,
Expand All @@ -180,7 +182,8 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {

if (
timeOfLastUpdateByGroup[nextUnbondedVaultGroup] != 0 &&
block.timestamp <= timeOfLastUpdateByGroup[curUnbondedVaultGroup] + unbondingPeriod + claimPeriod
block.timestamp <=
timeOfLastUpdateByGroup[curUnbondedVaultGroup] + unbondingPeriod + claimPeriod
) revert NoUpdateNeeded();

if (
Expand All @@ -189,7 +192,8 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
block.timestamp <= timeOfLastUpdateByGroup[curUnbondedVaultGroup - 1] + claimPeriod
) revert NoUpdateNeeded();

if (block.timestamp < timeOfLastUpdateByGroup[nextUnbondedVaultGroup] + unbondingPeriod) revert NoUpdateNeeded();
if (block.timestamp < timeOfLastUpdateByGroup[nextUnbondedVaultGroup] + unbondingPeriod)
revert NoUpdateNeeded();

(
uint256[] memory curGroupOpVaultsToUnbond,
Expand All @@ -198,8 +202,16 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
uint256 nextGroupComVaultsTotalUnbonded
) = abi.decode(_data, (uint256[], uint256, uint256[], uint256));

operatorVCS.updateVaultGroups(curGroupOpVaultsToUnbond, nextUnbondedVaultGroup, nextGroupOpVaultsTotalUnbonded);
communityVCS.updateVaultGroups(curGroupComVaultsToUnbond, nextUnbondedVaultGroup, nextGroupComVaultsTotalUnbonded);
operatorVCS.updateVaultGroups(
curGroupOpVaultsToUnbond,
nextUnbondedVaultGroup,
nextGroupOpVaultsTotalUnbonded
);
communityVCS.updateVaultGroups(
curGroupComVaultsToUnbond,
nextUnbondedVaultGroup,
nextGroupComVaultsTotalUnbonded
);

timeOfLastUpdateByGroup[curUnbondedVaultGroup] = uint64(block.timestamp);
curUnbondedVaultGroup = uint64(nextUnbondedVaultGroup);
Expand All @@ -212,11 +224,10 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
* @return vault deposit order
* @return total deposit space across returned vaults
*/
function _getVaultDepositOrder(IVaultControllerStrategy _vcs, uint256 _toDeposit)
internal
view
returns (uint64[] memory, uint256)
{
function _getVaultDepositOrder(
IVaultControllerStrategy _vcs,
uint256 _toDeposit
) internal view returns (uint64[] memory, uint256) {
address[] memory vaults = _vcs.getVaults();
if (vaults.length == 0) return (new uint64[](0), 0);

Expand All @@ -240,7 +251,9 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
++totalVaultsAdded;
(uint256 withdrawalIndex, ) = _vcs.vaultGroups(groupDepositIndex % numVaultGroups);
uint256 deposits = IVault(vaults[groupDepositIndex]).getPrincipalDeposits();
if (deposits != maxDeposits && (groupDepositIndex != withdrawalIndex || deposits == 0)) {
if (
deposits != maxDeposits && (groupDepositIndex != withdrawalIndex || deposits == 0)
) {
totalDepositsAdded += maxDeposits - deposits;
}
}
Expand All @@ -253,7 +266,8 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
if (j != groupDepositIndex && deposits != maxDeposits) {
vaultDepositOrder[totalVaultsAdded] = j;
++totalVaultsAdded;
if (j != withdrawalIndex || deposits == 0) totalDepositsAdded += maxDeposits - deposits;
if (j != withdrawalIndex || deposits == 0)
totalDepositsAdded += maxDeposits - deposits;
if (totalDepositsAdded >= _toDeposit) break;
}
}
Expand All @@ -278,11 +292,10 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
* @return vault withdrawal order
* @return total withdrawal space across returned vaults
*/
function _getVaultWithdrawalOrder(IVaultControllerStrategy _vcs, uint256 _toWithdraw)
internal
view
returns (uint64[] memory, uint256)
{
function _getVaultWithdrawalOrder(
IVaultControllerStrategy _vcs,
uint256 _toWithdraw
) internal view returns (uint64[] memory, uint256) {
address[] memory vaults = _vcs.getVaults();
(, , , uint64 maxVaultIndex) = _vcs.globalVaultState();
(uint64 withdrawalIndex, ) = _vcs.vaultGroups(curUnbondedVaultGroup);
Expand Down Expand Up @@ -327,15 +340,22 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
* @return list of vaults to unbond in current vault group
* @return total unbonded across all vaults in next vault group
*/
function _getVaultUpdateData(IVaultControllerStrategy _vcs, uint256 _nextUnbondedVaultGroup)
internal
view
returns (uint256[] memory, uint256)
{
function _getVaultUpdateData(
IVaultControllerStrategy _vcs,
uint256 _nextUnbondedVaultGroup
) internal view returns (uint256[] memory, uint256) {
address[] memory vaults = _vcs.getVaults();
uint256[] memory curGroupVaultsToUnbond = _getNonEmptyVaults(vaults, numVaultGroups, curUnbondedVaultGroup);
uint256[] memory curGroupVaultsToUnbond = _getNonEmptyVaults(
vaults,
numVaultGroups,
curUnbondedVaultGroup
);

uint256 nextGroupTotalUnbonded = _getTotalUnbonded(vaults, numVaultGroups, _nextUnbondedVaultGroup);
uint256 nextGroupTotalUnbonded = _getTotalUnbonded(
vaults,
numVaultGroups,
_nextUnbondedVaultGroup
);

return (curGroupVaultsToUnbond, nextGroupTotalUnbonded);
}
Expand Down Expand Up @@ -407,7 +427,9 @@ contract FundFlowController is UUPSUpgradeable, OwnableUpgradeable {
* @param _values list of values
* @return sorted list of indexes
*/
function _sortIndexesDescending(uint256[] memory _values) internal pure returns (uint256[] memory) {
function _sortIndexesDescending(
uint256[] memory _values
) internal pure returns (uint256[] memory) {
uint256 n = _values.length;

uint256[] memory indexes = new uint256[](n);
Expand Down
10 changes: 1 addition & 9 deletions contracts/linkStaking/interfaces/IVaultControllerStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ interface IVaultControllerStrategy {

function vaultGroups(uint256 _vaultGroupIndex) external view returns (uint64, uint128);

function globalVaultState()
external
view
returns (
uint64,
uint64,
uint64,
uint64
);
function globalVaultState() external view returns (uint64, uint64, uint64, uint64);

function updateVaultGroups(
uint256[] calldata _curGroupVaultsToUnbond,
Expand Down

0 comments on commit aa0efea

Please sign in to comment.