Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add return value for migrated token amount (SC-17122) #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions contracts/Migrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ contract Migrator is IMigrator {
tokenSplitScalar = scalar_;
}

function migrate(uint256 amount_) external override {
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 {
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");

require(ERC20Helper.transferFrom(oldToken, owner_, address(this), amount_), "M:M:TRANSFER_FROM_FAILED");
require(ERC20Helper.transfer(newToken, owner_, amount_ * tokenSplitScalar), "M:M:TRANSFER_FAILED");
newTokenAmount_ = oldTokenAmount_ * tokenSplitScalar;

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 {
Expand Down
12 changes: 7 additions & 5 deletions contracts/interfaces/IMigrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 oldTokenAmount_ The amount of oldToken to swap for newToken.
* @return newTokenAmount_ The amount of newToken received.
*/
function migrate(uint256 amount_) external;
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.
* @param owner_ The address of the owner of the oldToken.
* @param oldTokenAmount_ The amount of oldToken to swap for newToken.
* @return newTokenAmount_ The amount of newToken received.
*/
function migrate(address owner_, uint256 amount_) external;
function migrate(address owner_, uint256 oldTokenAmount_) external returns (uint256 newTokenAmount_);

/**
* @dev Set the migrator to active or inactive.
Expand Down
Loading