Skip to content

Commit

Permalink
feat: remove reentrancy guards from mint functions
Browse files Browse the repository at this point in the history
they didn't add any value as the mint functions
only interact with trusted contracts and tokens
  • Loading branch information
chapati23 committed Oct 15, 2024
1 parent 3409a44 commit cf48d9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
16 changes: 5 additions & 11 deletions contracts/goodDollar/GoodDollarExpansionController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { IERC20 } from "openzeppelin-contracts-next/contracts/token/ERC20/IERC20
import { IGoodDollar } from "contracts/goodDollar/interfaces/IGoodProtocol.sol";
import { IDistributionHelper } from "contracts/goodDollar/interfaces/IGoodProtocol.sol";

import { ReentrancyGuard } from "openzeppelin-contracts-next/contracts/security/ReentrancyGuard.sol";
import { PausableUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/security/PausableUpgradeable.sol";
import { OwnableUpgradeable } from "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol";
import { unwrap, wrap, powu } from "prb/math/UD60x18.sol";
Expand All @@ -17,12 +16,7 @@ import { unwrap, wrap, powu } from "prb/math/UD60x18.sol";
* @title GoodDollarExpansionController
* @notice Provides functionality to expand the supply of GoodDollars.
*/
contract GoodDollarExpansionController is
IGoodDollarExpansionController,
PausableUpgradeable,
OwnableUpgradeable,
ReentrancyGuard
{
contract GoodDollarExpansionController is IGoodDollarExpansionController, PausableUpgradeable, OwnableUpgradeable {
/* ==================== State Variables ==================== */

// MAX_WEIGHT is the max rate that can be assigned to an exchange
Expand Down Expand Up @@ -163,7 +157,7 @@ contract GoodDollarExpansionController is
* @param exchangeId The id of the exchange to mint UBI for.
* @param reserveInterest The amount of reserve tokens collected from interest.
*/
function mintUBIFromInterest(bytes32 exchangeId, uint256 reserveInterest) external nonReentrant {
function mintUBIFromInterest(bytes32 exchangeId, uint256 reserveInterest) external {
require(reserveInterest > 0, "reserveInterest must be greater than 0");
IBancorExchangeProvider.PoolExchange memory exchange = IBancorExchangeProvider(address(goodDollarExchangeProvider))
.getPoolExchange(exchangeId);
Expand All @@ -180,7 +174,7 @@ contract GoodDollarExpansionController is
* @param exchangeId The id of the exchange to mint UBI for.
* @return amountMinted The amount of UBI tokens minted.
*/
function mintUBIFromReserveBalance(bytes32 exchangeId) external nonReentrant returns (uint256 amountMinted) {
function mintUBIFromReserveBalance(bytes32 exchangeId) external returns (uint256 amountMinted) {
IBancorExchangeProvider.PoolExchange memory exchange = IBancorExchangeProvider(address(goodDollarExchangeProvider))
.getPoolExchange(exchangeId);

Expand All @@ -199,7 +193,7 @@ contract GoodDollarExpansionController is
* @param exchangeId The id of the exchange to mint UBI for.
* @return amountMinted The amount of UBI tokens minted.
*/
function mintUBIFromExpansion(bytes32 exchangeId) external nonReentrant returns (uint256 amountMinted) {
function mintUBIFromExpansion(bytes32 exchangeId) external returns (uint256 amountMinted) {
ExchangeExpansionConfig memory config = getExpansionConfig(exchangeId);
IBancorExchangeProvider.PoolExchange memory exchange = IBancorExchangeProvider(address(goodDollarExchangeProvider))
.getPoolExchange(exchangeId);
Expand Down Expand Up @@ -233,7 +227,7 @@ contract GoodDollarExpansionController is
* @param to The address of the recipient.
* @param amount The amount of tokens to mint.
*/
function mintRewardFromRR(bytes32 exchangeId, address to, uint256 amount) external onlyAvatar nonReentrant {
function mintRewardFromRR(bytes32 exchangeId, address to, uint256 amount) external onlyAvatar {
require(to != address(0), "Invalid to address");
require(amount > 0, "Amount must be greater than 0");
IBancorExchangeProvider.PoolExchange memory exchange = IBancorExchangeProvider(address(goodDollarExchangeProvider))
Expand Down
18 changes: 9 additions & 9 deletions test/unit/goodDollar/GoodDollarExpansionController.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ contract GoodDollarExpansionControllerTest_mintUBIFromExpansion is GoodDollarExp
}
}

contract GoodDollarExpansionControllerTest_mintRewardFromRR is GoodDollarExpansionControllerTest {
contract GoodDollarExpansionControllerTest_mintRewardFromReserveRatio is GoodDollarExpansionControllerTest {
GoodDollarExpansionController expansionController;

function setUp() public override {
Expand Down Expand Up @@ -595,25 +595,25 @@ contract GoodDollarExpansionControllerTest_mintRewardFromRR is GoodDollarExpansi
);
}

function test_mintRewardFromRR_whenCallerIsNotAvatar_shouldRevert() public {
function test_mintRewardFromReserveRatio_whenCallerIsNotAvatar_shouldRevert() public {
vm.prank(makeAddr("NotAvatar"));
vm.expectRevert("Only Avatar can call this function");
expansionController.mintRewardFromRR(exchangeId, makeAddr("To"), 1000e18);
expansionController.mintRewardFromReserveRatio(exchangeId, makeAddr("To"), 1000e18);
}

function test_mintRewardFromRR_whenToIsZero_shouldRevert() public {
function test_mintRewardFromReserveRatio_whenToIsZero_shouldRevert() public {
vm.prank(avatarAddress);
vm.expectRevert("Invalid to address");
expansionController.mintRewardFromRR(exchangeId, address(0), 1000e18);
expansionController.mintRewardFromReserveRatio(exchangeId, address(0), 1000e18);
}

function test_mintRewardFromRR_whenAmountIs0_shouldRevert() public {
function test_mintRewardFromReserveRatio_whenAmountIs0_shouldRevert() public {
vm.prank(avatarAddress);
vm.expectRevert("Amount must be greater than 0");
expansionController.mintRewardFromRR(exchangeId, makeAddr("To"), 0);
expansionController.mintRewardFromReserveRatio(exchangeId, makeAddr("To"), 0);
}

function test_mintRewardFromRR_whenCallerIsAvatar_shouldMintAndEmit() public {
function test_mintRewardFromReserveRatio_whenCallerIsAvatar_shouldMintAndEmit() public {
uint256 amountToMint = 1000e18;
address to = makeAddr("To");
uint256 toBalanceBefore = token.balanceOf(to);
Expand All @@ -622,7 +622,7 @@ contract GoodDollarExpansionControllerTest_mintRewardFromRR is GoodDollarExpansi
emit RewardMinted(exchangeId, to, amountToMint);

vm.prank(avatarAddress);
expansionController.mintRewardFromRR(exchangeId, to, amountToMint);
expansionController.mintRewardFromReserveRatio(exchangeId, to, amountToMint);

assertEq(token.balanceOf(to), toBalanceBefore + amountToMint);
}
Expand Down

0 comments on commit cf48d9a

Please sign in to comment.