Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: $GD resolved large reward issue #544

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading