From 82ad429edcf9d2e6347bec54be8e03ea90fa99a6 Mon Sep 17 00:00:00 2001 From: 0xfarhaan <59924029+0xfarhaan@users.noreply.github.com> Date: Wed, 26 Jun 2024 11:57:35 +0100 Subject: [PATCH 1/2] feat: Add return value for migrated token amount --- contracts/Migrator.sol | 10 ++++++---- contracts/interfaces/IMigrator.sol | 12 +++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/contracts/Migrator.sol b/contracts/Migrator.sol index 5a98a37..6a2593b 100644 --- a/contracts/Migrator.sol +++ b/contracts/Migrator.sol @@ -29,16 +29,18 @@ contract Migrator is IMigrator { tokenSplitScalar = scalar_; } - function migrate(uint256 amount_) external override { - migrate(msg.sender, amount_); + function migrate(uint256 amount_) external override returns (uint256 migratedAmount_) { + migratedAmount_ = migrate(msg.sender, amount_); } - function migrate(address owner_, uint256 amount_) public override { + function migrate(address owner_, uint256 amount_) public override returns (uint256 migratedAmount_) { require(active, "M:M:INACTIVE"); require(amount_ != uint256(0), "M:M:ZERO_AMOUNT"); + migratedAmount_ = amount_ * tokenSplitScalar; + require(ERC20Helper.transferFrom(oldToken, owner_, address(this), amount_), "M:M:TRANSFER_FROM_FAILED"); - require(ERC20Helper.transfer(newToken, owner_, amount_ * tokenSplitScalar), "M:M:TRANSFER_FAILED"); + require(ERC20Helper.transfer(newToken, owner_, migratedAmount_), "M:M:TRANSFER_FAILED"); } function setActive(bool active_) external override { diff --git a/contracts/interfaces/IMigrator.sol b/contracts/interfaces/IMigrator.sol index 9e433ef..cf1f318 100644 --- a/contracts/interfaces/IMigrator.sol +++ b/contracts/interfaces/IMigrator.sol @@ -29,16 +29,18 @@ interface IMigrator { /** * @dev Exchange the oldToken for the same amount of newToken. - * @param amount_ The amount of oldToken to swap for newToken. + * @param amount_ The amount of oldToken to swap for newToken. + * @return migratedAmount_ The amount of newToken received. */ - function migrate(uint256 amount_) external; + function migrate(uint256 amount_) external returns (uint256 migratedAmount_); /** * @dev Exchange the oldToken for the same amount of newToken. - * @param owner_ The address of the owner of the oldToken. - * @param amount_ The amount of oldToken to swap for newToken. + * @param owner_ The address of the owner of the oldToken. + * @param amount_ The amount of oldToken to swap for newToken. + * @return migratedAmount_ The amount of newToken received. */ - function migrate(address owner_, uint256 amount_) external; + function migrate(address owner_, uint256 amount_) external returns (uint256 migratedAmount_); /** * @dev Set the migrator to active or inactive. From a63ebf4896e8959f50e886f50d3f2bede7ad406e Mon Sep 17 00:00:00 2001 From: 0xfarhaan <59924029+0xfarhaan@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:01:04 +0100 Subject: [PATCH 2/2] feat: Update interface for old/new token amounts --- contracts/Migrator.sol | 16 ++++++++-------- contracts/interfaces/IMigrator.sol | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/contracts/Migrator.sol b/contracts/Migrator.sol index 6a2593b..c76f8eb 100644 --- a/contracts/Migrator.sol +++ b/contracts/Migrator.sol @@ -29,18 +29,18 @@ contract Migrator is IMigrator { tokenSplitScalar = scalar_; } - function migrate(uint256 amount_) external override returns (uint256 migratedAmount_) { - migratedAmount_ = migrate(msg.sender, amount_); + function migrate(uint256 oldTokenAmount_) external override returns (uint256 newTokenAmount_) { + newTokenAmount_ = migrate(msg.sender, oldTokenAmount_); } - function migrate(address owner_, uint256 amount_) public override returns (uint256 migratedAmount_) { - require(active, "M:M:INACTIVE"); - require(amount_ != uint256(0), "M:M:ZERO_AMOUNT"); + function migrate(address owner_, uint256 oldTokenAmount_) public override returns (uint256 newTokenAmount_) { + require(active, "M:M:INACTIVE"); + require(oldTokenAmount_ != uint256(0), "M:M:ZERO_AMOUNT"); - migratedAmount_ = amount_ * tokenSplitScalar; + newTokenAmount_ = oldTokenAmount_ * tokenSplitScalar; - require(ERC20Helper.transferFrom(oldToken, owner_, address(this), amount_), "M:M:TRANSFER_FROM_FAILED"); - require(ERC20Helper.transfer(newToken, owner_, migratedAmount_), "M:M:TRANSFER_FAILED"); + require(ERC20Helper.transferFrom(oldToken, owner_, address(this), oldTokenAmount_), "M:M:TRANSFER_FROM_FAILED"); + require(ERC20Helper.transfer(newToken, owner_, newTokenAmount_), "M:M:TRANSFER_FAILED"); } function setActive(bool active_) external override { diff --git a/contracts/interfaces/IMigrator.sol b/contracts/interfaces/IMigrator.sol index cf1f318..801887c 100644 --- a/contracts/interfaces/IMigrator.sol +++ b/contracts/interfaces/IMigrator.sol @@ -29,18 +29,18 @@ interface IMigrator { /** * @dev Exchange the oldToken for the same amount of newToken. - * @param amount_ The amount of oldToken to swap for newToken. - * @return migratedAmount_ The amount of newToken received. + * @param oldTokenAmount_ The amount of oldToken to swap for newToken. + * @return newTokenAmount_ The amount of newToken received. */ - function migrate(uint256 amount_) external returns (uint256 migratedAmount_); + function migrate(uint256 oldTokenAmount_) external returns (uint256 newTokenAmount_); /** * @dev Exchange the oldToken for the same amount of newToken. * @param owner_ The address of the owner of the oldToken. - * @param amount_ The amount of oldToken to swap for newToken. - * @return migratedAmount_ The amount of newToken received. + * @param oldTokenAmount_ The amount of oldToken to swap for newToken. + * @return newTokenAmount_ The amount of newToken received. */ - function migrate(address owner_, uint256 amount_) external returns (uint256 migratedAmount_); + function migrate(address owner_, uint256 oldTokenAmount_) external returns (uint256 newTokenAmount_); /** * @dev Set the migrator to active or inactive.