-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from jpegd/token-migration
Token migration pr
- Loading branch information
Showing
12 changed files
with
1,084 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.4; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||
|
||
contract TokenMigration is Ownable, ReentrancyGuard { | ||
error ZeroAddress(); | ||
error ZeroAmount(); | ||
|
||
event TokensMigrated( | ||
address indexed account, | ||
uint256 newTokenAmount, | ||
uint256 oldTokenAmount | ||
); | ||
|
||
IERC20 public immutable NEW_TOKEN; | ||
IERC20 public immutable OLD_TOKEN; | ||
|
||
uint256 internal immutable NEW_SUPPLY; | ||
uint256 internal immutable OLD_SUPPLY; | ||
|
||
constructor(address _newToken, address _oldToken) { | ||
if (_newToken == address(0) || _oldToken == address(0)) | ||
revert ZeroAddress(); | ||
|
||
NEW_TOKEN = IERC20(_newToken); | ||
OLD_TOKEN = IERC20(_oldToken); | ||
|
||
NEW_SUPPLY = IERC20(_newToken).totalSupply(); | ||
OLD_SUPPLY = IERC20(_oldToken).totalSupply(); | ||
} | ||
|
||
function migrate(uint256 _amount) external nonReentrant { | ||
if (_amount == 0) revert ZeroAmount(); | ||
|
||
uint256 _amountToTransfer = (_amount * NEW_SUPPLY) / OLD_SUPPLY; | ||
|
||
OLD_TOKEN.transferFrom(msg.sender, address(this), _amount); | ||
NEW_TOKEN.transfer(msg.sender, _amountToTransfer); | ||
|
||
emit TokensMigrated(msg.sender, _amountToTransfer, _amount); | ||
} | ||
|
||
function withdrawOldToken(uint256 _amount) external onlyOwner { | ||
OLD_TOKEN.transfer(msg.sender, _amount); | ||
} | ||
|
||
function withdrawNewToken(uint256 _amount) external onlyOwner { | ||
NEW_TOKEN.transfer(msg.sender, _amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.4; | ||
|
||
import "../vaults/NFTValueProvider.sol"; | ||
|
||
contract MockNFTValueProviderMigration is NFTValueProvider { | ||
function setJPEG(IERC20Upgradeable _jpeg) external { | ||
jpeg = _jpeg; | ||
} | ||
|
||
function setLegacyTraitLock(uint256 _index, uint256 _lockedValue) external { | ||
traitBoostPositions[_index].isNewToken = false; | ||
traitBoostPositions[_index].lockedValue = _lockedValue; | ||
} | ||
|
||
function setLegacyLTVLock(uint256 _index, uint256 _lockedValue) external { | ||
ltvBoostPositions[_index].isNewToken = false; | ||
ltvBoostPositions[_index].lockedValue = _lockedValue; | ||
} | ||
} |
Oops, something went wrong.