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

Token migration pr #73

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
53 changes: 53 additions & 0 deletions contracts/sale/TokenMigration.sol
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);
}
}
20 changes: 20 additions & 0 deletions contracts/test/MockNFTValueProviderMigration.sol
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;
}
}
77 changes: 77 additions & 0 deletions contracts/tokens/JPGD.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol";
import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/utils/Context.sol";

contract JPGD is
Context,
AccessControlEnumerable,
ERC20Burnable,
ERC20Pausable
{
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

constructor() ERC20("JPEG\xE2\x80\x99d", "JPGD") {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

/// @dev Creates `amount` tokens and assigns them to `account`, increasing
/// the total supply.
///
/// Emits a {Transfer} event with `from` set to the zero address.
///
/// Requirements:
///
/// - `account` cannot be the zero address.
///
function mint(address to, uint256 amount) external {
require(
hasRole(MINTER_ROLE, _msgSender()),
"PETH: must have minter role to mint"
);
_mint(to, amount);
}

/// @dev Triggers stopped state.
///
/// Requirements:
///
/// - The contract must not be paused.
///
function pause() external {
require(
hasRole(PAUSER_ROLE, _msgSender()),
"PETH: must have pauser role to pause"
);
_pause();
}

/// @dev Returns to normal state.
///
/// Requirements:
///
/// - The contract must be paused.
///
function unpause() external {
require(
hasRole(PAUSER_ROLE, _msgSender()),
"PETH: must have pauser role to unpause"
);
_unpause();
}

//override required by solidity
/// @inheritdoc ERC20Pausable
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual override(ERC20, ERC20Pausable) {
super._beforeTokenTransfer(from, to, amount);
}
}
Loading