Skip to content

Commit

Permalink
refactor: rework local variables to avoid stack to deep error
Browse files Browse the repository at this point in the history
  • Loading branch information
xorsal committed Oct 31, 2024
1 parent eae4ea1 commit 618cc36
Showing 1 changed file with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,39 +159,43 @@ contract BondEscalationResolutionModule is AccessControllerModule, IBondEscalati

if (_escalation.resolution == Resolution.Unresolved) revert BondEscalationResolutionModule_NotResolved();

uint256 _pledgerBalanceBefore;
uint256 _pledgerProportion;
uint256 _amountToRelease;
RequestParameters memory _params = decodeRequestData(_request.resolutionModuleData);

address _pledger = _accessControl.user;

{
uint256 _pledgerBalanceBefore;
uint256 _reward;

if (_escalation.resolution == Resolution.DisputerWon) {
_pledgerBalanceBefore = pledgesForDispute[_disputeId][_accessControl.user];
pledgesForDispute[_disputeId][_accessControl.user] -= _pledgerBalanceBefore;
_pledgerProportion = FixedPointMathLib.mulDivDown(_pledgerBalanceBefore, BASE, _escalation.pledgesFor);
_reward = FixedPointMathLib.mulDivDown(_escalation.pledgesAgainst, _pledgerProportion, BASE);
_amountToRelease = _reward + _pledgerBalanceBefore;
_pledgerBalanceBefore = pledgesForDispute[_disputeId][_pledger];
pledgesForDispute[_disputeId][_pledger] -= _pledgerBalanceBefore;
_reward = FixedPointMathLib.mulDivDown(
_escalation.pledgesAgainst,
FixedPointMathLib.mulDivDown(_pledgerBalanceBefore, BASE, _escalation.pledgesFor),
BASE
);
_claimPledge({
_request: _request,
_dispute: _dispute,
_amountToRelease: _amountToRelease,
_pledge: _accessControl.user,
_amountToRelease: _reward + _pledgerBalanceBefore,
_pledger: _pledger,
_resolution: _escalation.resolution,
_params: _params
});
} else if (_escalation.resolution == Resolution.DisputerLost) {
_pledgerBalanceBefore = pledgesAgainstDispute[_disputeId][_accessControl.user];
pledgesAgainstDispute[_disputeId][_accessControl.user] -= _pledgerBalanceBefore;
_pledgerProportion = FixedPointMathLib.mulDivDown(_pledgerBalanceBefore, BASE, _escalation.pledgesAgainst);
_reward = FixedPointMathLib.mulDivDown(_escalation.pledgesFor, _pledgerProportion, BASE);
_amountToRelease = _reward + _pledgerBalanceBefore;
_pledgerBalanceBefore = pledgesAgainstDispute[_disputeId][_pledger];
pledgesAgainstDispute[_disputeId][_pledger] -= _pledgerBalanceBefore;
_reward = FixedPointMathLib.mulDivDown(
_escalation.pledgesFor,
FixedPointMathLib.mulDivDown(_pledgerBalanceBefore, BASE, _escalation.pledgesAgainst),
BASE
);
_claimPledge({
_request: _request,
_dispute: _dispute,
_amountToRelease: _amountToRelease,
_pledge: _accessControl.user,
_amountToRelease: _reward + _pledgerBalanceBefore,
_pledger: _pledger,
_resolution: _escalation.resolution,
_params: _params
});
Expand All @@ -200,28 +204,28 @@ contract BondEscalationResolutionModule is AccessControllerModule, IBondEscalati

if (_escalation.resolution == Resolution.NoResolution) {
{
uint256 _pledgerBalanceFor = pledgesForDispute[_disputeId][_accessControl.user];
uint256 _pledgerBalanceFor = pledgesForDispute[_disputeId][_pledger];
if (_pledgerBalanceFor > 0) {
pledgesForDispute[_disputeId][_accessControl.user] -= _pledgerBalanceFor;
pledgesForDispute[_disputeId][_pledger] -= _pledgerBalanceFor;
_claimPledge({
_request: _request,
_dispute: _dispute,
_amountToRelease: _pledgerBalanceFor,
_pledge: _accessControl.user,
_pledger: _pledger,
_resolution: _escalation.resolution,
_params: _params
});
}
}
{
uint256 _pledgerBalanceAgainst = pledgesAgainstDispute[_disputeId][_accessControl.user];
uint256 _pledgerBalanceAgainst = pledgesAgainstDispute[_disputeId][_pledger];
if (_pledgerBalanceAgainst > 0) {
pledgesAgainstDispute[_disputeId][_accessControl.user] -= _pledgerBalanceAgainst;
pledgesAgainstDispute[_disputeId][_pledger] -= _pledgerBalanceAgainst;
_claimPledge({
_request: _request,
_dispute: _dispute,
_amountToRelease: _pledgerBalanceAgainst,
_pledge: _accessControl.user,
_pledger: _pledger,
_resolution: _escalation.resolution,
_params: _params
});
Expand Down

0 comments on commit 618cc36

Please sign in to comment.