From 1ca572bf8ebaf3815c35ac703db9c08d0dcb9c66 Mon Sep 17 00:00:00 2001 From: Ivan Zhelyazkov Date: Thu, 16 Nov 2023 10:15:43 +0200 Subject: [PATCH] carbon pol eth conversion - review fixes --- contracts/pol/CarbonPOL.sol | 5 +++-- contracts/pol/interfaces/ICarbonPOL.sol | 6 +++--- test/forge/CarbonPOL.t.sol | 11 ++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/contracts/pol/CarbonPOL.sol b/contracts/pol/CarbonPOL.sol index 161137a0..0e374c1d 100644 --- a/contracts/pol/CarbonPOL.sol +++ b/contracts/pol/CarbonPOL.sol @@ -45,8 +45,9 @@ contract CarbonPOL is ICarbonPOL, Upgradeable, ReentrancyGuardUpgradeable, Utils /** * @dev used to initialize the implementation */ - constructor(Token bntInit) { - _bnt = bntInit; + constructor(Token initBnt) { + _validAddress(Token.unwrap(initBnt)); + _bnt = initBnt; // initialize implementation initialize(); } diff --git a/contracts/pol/interfaces/ICarbonPOL.sol b/contracts/pol/interfaces/ICarbonPOL.sol index b0b80702..d69eca40 100644 --- a/contracts/pol/interfaces/ICarbonPOL.sol +++ b/contracts/pol/interfaces/ICarbonPOL.sol @@ -82,14 +82,14 @@ interface ICarbonPOL is IUpgradeable { function tradingEnabled(Token token) external view returns (bool); /** - * @notice returns the expected trade output (tokens received) given an eth amount sent for a token - * @notice if token == ETH, return how much bnt will be sent given an eth amount received + * @notice returns the expected trade output (tokens received) given an ETH amount sent for a token + * @notice if token == ETH, return how much BNT will be sent given an ETH amount received */ function expectedTradeReturn(Token token, uint128 ethAmount) external view returns (uint128 tokenAmount); /** * @notice returns the expected trade input (how much eth to send) given a token amount received - * @notice if token == ETH, return how much eth will be received given a bnt amount sent + * @notice if token == ETH, return how much ETH will be received given a BNT amount sent */ function expectedTradeInput(Token token, uint128 tokenAmount) external view returns (uint128 ethAmount); diff --git a/test/forge/CarbonPOL.t.sol b/test/forge/CarbonPOL.t.sol index b1c3ac6f..8423a34f 100644 --- a/test/forge/CarbonPOL.t.sol +++ b/test/forge/CarbonPOL.t.sol @@ -6,11 +6,12 @@ import { Address } from "@openzeppelin/contracts/utils/Address.sol"; import { TestFixture } from "./TestFixture.t.sol"; import { POLTestCaseParser } from "./POLTestCaseParser.t.sol"; -import { AccessDenied, ZeroValue } from "../../contracts/utility/Utils.sol"; +import { AccessDenied, ZeroValue, InvalidAddress } from "../../contracts/utility/Utils.sol"; import { Token, NATIVE_TOKEN } from "../../contracts/token/Token.sol"; import { TestReenterCarbonPOL } from "../../contracts/helpers/TestReenterCarbonPOL.sol"; import { ICarbonPOL } from "../../contracts/pol/interfaces/ICarbonPOL.sol"; +import { CarbonPOL } from "../../contracts/pol/CarbonPOL.sol"; contract CarbonPOLTest is TestFixture { using Address for address payable; @@ -89,6 +90,14 @@ contract CarbonPOLTest is TestFixture { carbonPOL.initialize(); } + /** + * @dev test should revert when deploying CarbonPOL with an invalid bnt address + */ + function testShouldRevertWhenDeployingWithInvalidBNTAddress() public { + vm.expectRevert(InvalidAddress.selector); + new CarbonPOL(Token.wrap(address(0))); + } + /** * @dev market price multiply tests */