From e712bd2082ed42cc2ef08c0da80450cb279c59cd Mon Sep 17 00:00:00 2001 From: JG Carvalho Date: Thu, 6 Jun 2024 10:53:08 -0400 Subject: [PATCH] fix: adjust PR comments --- contracts/Migrator.sol | 13 +++++++------ contracts/interfaces/IMigrator.sol | 4 ++-- tests/Migrator.t.sol | 12 +++++++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/contracts/Migrator.sol b/contracts/Migrator.sol index 43e3706..c0c7614 100644 --- a/contracts/Migrator.sol +++ b/contracts/Migrator.sol @@ -9,18 +9,19 @@ import { IMigrator } from "./interfaces/IMigrator.sol"; contract Migrator is IMigrator { - uint256 public immutable override TOKEN_SPLIT_SCALAR; - address public immutable override newToken; address public immutable override oldToken; + uint256 public immutable override tokenSplitScalar; + constructor(address oldToken_, address newToken_, uint256 scalar_) { + require(scalar_ > 0, "M:C:ZERO_SCALAR"); require(IERC20Like(newToken_).decimals() == IERC20Like(oldToken_).decimals(), "M:C:DECIMAL_MISMATCH"); oldToken = oldToken_; newToken = newToken_; - TOKEN_SPLIT_SCALAR = scalar_; + tokenSplitScalar = scalar_; } function migrate(uint256 amount_) external override { @@ -28,10 +29,10 @@ contract Migrator is IMigrator { } function migrate(address owner_, uint256 amount_) public override { - require(amount_ != uint256(0), "M:M:ZERO_AMOUNT"); + require(amount_ != uint256(0), "M:M:ZERO_AMOUNT"); - require(ERC20Helper.transferFrom(oldToken, owner_, address(this), amount_), "M:M:TRANSFER_FROM_FAILED"); - require(ERC20Helper.transfer(newToken, owner_, amount_ * TOKEN_SPLIT_SCALAR), "M:M:TRANSFER_FAILED"); + require(ERC20Helper.transferFrom(oldToken, owner_, address(this), amount_), "M:M:TRANSFER_FROM_FAILED"); + require(ERC20Helper.transfer(newToken, owner_, amount_ * tokenSplitScalar), "M:M:TRANSFER_FAILED"); } } diff --git a/contracts/interfaces/IMigrator.sol b/contracts/interfaces/IMigrator.sol index 2fb2158..6bf081f 100644 --- a/contracts/interfaces/IMigrator.sol +++ b/contracts/interfaces/IMigrator.sol @@ -30,8 +30,8 @@ interface IMigrator { /** * @dev Get the scalar value for token split. - * @return TOKEN_SPLIT_SCALAR_ The scalar value for token split. + * @return tokenSplitScalar_ The scalar value for token split. */ - function TOKEN_SPLIT_SCALAR() external view returns (uint256 TOKEN_SPLIT_SCALAR_); + function tokenSplitScalar() external view returns (uint256 tokenSplitScalar_); } diff --git a/tests/Migrator.t.sol b/tests/Migrator.t.sol index 149d982..8510fc7 100644 --- a/tests/Migrator.t.sol +++ b/tests/Migrator.t.sol @@ -9,6 +9,11 @@ import { Migrator } from "../contracts/Migrator.sol"; contract MigratorConstructorTest is Test { + function test_constructor_zeroScalar() external { + vm.expectRevert("M:C:ZERO_SCALAR"); + new Migrator(address(0), address(0), 0); + } + function test_constructor_mismatch_decimals() external { MockERC20 oldToken = new MockERC20("Old Token", "OT", 18); MockERC20 newToken = new MockERC20("New Token", "NT", 17); @@ -23,8 +28,9 @@ contract MigratorConstructorTest is Test { Migrator migrator = new Migrator(address(oldToken), address(newToken), 1); - assertEq(migrator.oldToken(), address(oldToken)); - assertEq(migrator.newToken(), address(newToken)); + assertEq(migrator.tokenSplitScalar(), 1); + assertEq(migrator.oldToken(), address(oldToken)); + assertEq(migrator.newToken(), address(newToken)); } } @@ -32,7 +38,7 @@ contract MigratorConstructorTest is Test { contract MigratorTest is Test { uint256 internal constant SCALAR = 10; - uint256 internal constant OLD_SUPPLY = 10_000_000 ether; + uint256 internal constant OLD_SUPPLY = 10_000_000e18; address account = makeAddr("account");