Skip to content

Commit

Permalink
fix: $GD resolved large reward issue (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyRy79261 authored Nov 25, 2024
1 parent d51019c commit b14b3e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contracts/goodDollar/GoodDollarExchangeProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ contract GoodDollarExchangeProvider is IGoodDollarExchangeProvider, BancorExchan
uint256 newRatioScaled = unwrap(numerator.div(denominator));

uint32 newRatioUint = uint32(newRatioScaled / 1e10);
require(newRatioUint > 0, "New ratio must be greater than 0");

exchanges[exchangeId].reserveRatio = newRatioUint;
exchanges[exchangeId].tokenSupply += rewardScaled;

Expand Down
9 changes: 9 additions & 0 deletions test/unit/goodDollar/GoodDollarExchangeProvider.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,15 @@ contract GoodDollarExchangeProviderTest_updateRatioForReward is GoodDollarExchan
exchangeId = exchangeProvider.createExchange(poolExchange);
}

function test_updateRatioForReward_whenNewRatioIsZero_shouldRevert() public {
// Use a very large reward that will make the denominator massive compared to numerator
uint256 veryLargeReward = type(uint256).max / 1e20; // Large but not large enough to overflow

vm.expectRevert("New ratio must be greater than 0");
vm.prank(expansionControllerAddress);
exchangeProvider.updateRatioForReward(exchangeId, veryLargeReward);
}

function test_updateRatioForReward_whenCallerIsNotExpansionController_shouldRevert() public {
vm.prank(makeAddr("NotExpansionController"));
vm.expectRevert("Only ExpansionController can call this function");
Expand Down

0 comments on commit b14b3e6

Please sign in to comment.