Skip to content

Commit

Permalink
fix: adjust PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
JGcarv committed Jun 6, 2024
1 parent 17470e7 commit e712bd2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
13 changes: 7 additions & 6 deletions contracts/Migrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ 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 {
migrate(msg.sender, amount_);
}

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");
}

}
4 changes: 2 additions & 2 deletions contracts/interfaces/IMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_);

}
12 changes: 9 additions & 3 deletions tests/Migrator.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -23,16 +28,17 @@ 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));
}

}

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");

Expand Down

0 comments on commit e712bd2

Please sign in to comment.