Skip to content

Commit

Permalink
carbon pol eth conversion - minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanzhelyazkov committed Nov 23, 2023
1 parent a2bc3a4 commit 7640d90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions contracts/pol/CarbonPOL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ contract CarbonPOL is ICarbonPOL, Upgradeable, ReentrancyGuardUpgradeable, Utils
function enableTradingETH(Price memory price) external onlyAdmin validPrice(price) {
_tradingStartTimes[NATIVE_TOKEN] = uint32(block.timestamp);
_initialPrice[NATIVE_TOKEN] = price;
_ethSaleAmount.current = _ethSaleAmount.initial;
_ethSaleAmount.current = address(this).balance > _ethSaleAmount.initial

This comment has been minimized.

Copy link
@lbeder

lbeder Nov 23, 2023

Collaborator

Super nitpick: you can use Math.min in all these references

? _ethSaleAmount.initial
: uint128(address(this).balance);
emit TradingEnabled(NATIVE_TOKEN, price);
}

Expand Down Expand Up @@ -410,7 +412,9 @@ contract CarbonPOL is ICarbonPOL, Upgradeable, ReentrancyGuardUpgradeable, Utils

// check if the new sale amount is below the current available eth sale amount
if (newEthSaleAmount < _ethSaleAmount.current) {

This comment has been minimized.

Copy link
@lbeder

lbeder Nov 23, 2023

Collaborator

What if newEthSaleAmount is larger than the available balance? Shouldn't it revert in this case?

This comment has been minimized.

Copy link
@ivanzhelyazkov

ivanzhelyazkov Nov 23, 2023

Author Collaborator

No, the initial sale amount shouldn't be related to the balance

_ethSaleAmount.current = newEthSaleAmount;
_ethSaleAmount.current = address(this).balance > newEthSaleAmount
? newEthSaleAmount
: uint128(address(this).balance);
}

emit EthSaleAmountUpdated(prevEthSaleAmount, newEthSaleAmount);
Expand Down
12 changes: 12 additions & 0 deletions test/forge/CarbonPOL.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ contract CarbonPOLTest is TestFixture {
carbonPOL.enableTradingETH(price);
}

/// @dev test enabling trading for eth should set the current sale amount properly
function testEnablingTradingForETHShouldSetTheCurrentSaleAmountProperly() public {
vm.startPrank(admin);
// set the initial sale amount to a value higher than the pol balance
carbonPOL.setEthSaleAmount(uint128(address(carbonPOL).balance * 2));
// enable trading for eth
carbonPOL.enableTradingETH(ICarbonPOL.Price({ sourceAmount: 100, targetAmount: 10000 }));
// check current eth sale amount is set to the contract balance
assertEq(carbonPOL.ethSaleAmount().current, address(carbonPOL).balance);
vm.stopPrank();
}

/// @dev test should revert when setting invalid price for a token
function testShouldRevertWhenSettingInvalidPriceForToken(uint256 i) public {
// pick one of these tokens to test
Expand Down

0 comments on commit 7640d90

Please sign in to comment.