Skip to content

Commit

Permalink
fix(contract): handle staking and redelegation failures gracefully (#…
Browse files Browse the repository at this point in the history
…1868)

Refactor staking and redelegation logic to use `call` for error
handling. This ensures the contract can handle failures without
reverting, improving system robustness. Changes include decoding
responses and conditionally updating state based on success.
  • Loading branch information
shuhuiluo authored Dec 18, 2024
1 parent 18f91da commit 6c875cb
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,26 @@ abstract contract MainnetDelegationBase is IMainnetDelegationBase {

uint256 depositId = ds.depositIdByDelegator[delegator];
if (depositId == 0) {
depositId = IRewardsDistribution(address(this)).stake(
SafeCastLib.toUint96(quantity),
operator,
delegator
(bool success, bytes memory retData) = address(this).call(
abi.encodeCall(
IRewardsDistribution.stake,
(SafeCastLib.toUint96(quantity), operator, delegator)
)
);
ds.depositIdByDelegator[delegator] = depositId;
if (success) {
depositId = abi.decode(retData, (uint256));
ds.depositIdByDelegator[delegator] = depositId;
}
} else {
IRewardsDistribution(address(this)).redelegate(depositId, operator);
IRewardsDistribution(address(this)).increaseStake(
depositId,
SafeCastLib.toUint96(quantity)
(bool success, ) = address(this).call(
abi.encodeCall(IRewardsDistribution.redelegate, (depositId, operator))
);
if (success) {
IRewardsDistribution(address(this)).increaseStake(
depositId,
SafeCastLib.toUint96(quantity)
);
}
}
}

Expand Down

0 comments on commit 6c875cb

Please sign in to comment.