Skip to content

Commit

Permalink
feat: Add return value for migrated token amount
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfarhaan committed Jun 26, 2024
1 parent d00bfcd commit 82ad429
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 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 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 {
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 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.
Expand Down

0 comments on commit 82ad429

Please sign in to comment.