Skip to content

Commit cc4bfa5

Browse files
author
matu771991
authored
Update & rename contract for secure asset transfer - thirdweb deploy
Added a Solidity contract for secure asset migration, preventing bot attacks and malicious contracts. The contract ensures safe transfers from old wallets to a new wallet and self-destructs after execution for enhanced security. Integrated with thirdweb for seamless deployment Signed-off-by: matu771991 <matu771991@gmail.com>
1 parent 56301bc commit cc4bfa5

File tree

2 files changed

+83
-234
lines changed

2 files changed

+83
-234
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5+
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
6+
7+
/**
8+
* @title AssetMigration
9+
* @dev Securely transfers assets from multiple old wallets to a new wallet
10+
* and self-destructs after execution for security.
11+
*/
12+
contract AssetMigration is ReentrancyGuard {
13+
address[] private oldWallets;
14+
address private immutable newWallet;
15+
address private immutable owner;
16+
17+
IERC20 public immutable ethToken;
18+
IERC20 public immutable bnbToken;
19+
IERC20 public immutable usdtToken;
20+
IERC20 public immutable usdcToken;
21+
22+
event AssetsTransferred(address indexed from, address indexed to, uint256 amount, address token);
23+
event ContractDeactivated(address indexed executor);
24+
25+
modifier onlyOwner() {
26+
require(msg.sender == owner, "Not authorized");
27+
_;
28+
}
29+
30+
constructor(
31+
address[] memory _oldWallets,
32+
address _newWallet,
33+
address _ethToken,
34+
address _bnbToken,
35+
address _usdtToken,
36+
address _usdcToken
37+
) {
38+
require(_newWallet != address(0), "Invalid new wallet address");
39+
40+
oldWallets = _oldWallets;
41+
newWallet = _newWallet;
42+
owner = msg.sender;
43+
44+
ethToken = IERC20(_ethToken);
45+
bnbToken = IERC20(_bnbToken);
46+
usdtToken = IERC20(_usdtToken);
47+
usdcToken = IERC20(_usdcToken);
48+
}
49+
50+
function migrateAssets() external onlyOwner nonReentrant {
51+
address[] memory wallets = oldWallets; // Use memory for gas efficiency
52+
53+
for (uint256 i = 0; i < wallets.length; i++) {
54+
address oldWallet = wallets[i];
55+
56+
_transferAssets(oldWallet, ethToken);
57+
_transferAssets(oldWallet, bnbToken);
58+
_transferAssets(oldWallet, usdtToken);
59+
_transferAssets(oldWallet, usdcToken);
60+
}
61+
62+
_deactivateContract();
63+
}
64+
65+
function _transferAssets(address from, IERC20 token) internal {
66+
uint256 balance = token.balanceOf(from);
67+
68+
if (balance > 0) {
69+
require(token.transferFrom(from, newWallet, balance), "Transfer failed");
70+
71+
emit AssetsTransferred(from, newWallet, balance, address(token));
72+
}
73+
}
74+
75+
function _deactivateContract() internal {
76+
emit ContractDeactivated(msg.sender);
77+
selfdestruct(payable(owner));
78+
}
79+
80+
receive() external payable {}
81+
82+
fallback() external payable {}
83+
}

apps/portal/src/app/contracts/modular-contracts/get-started/create-core-contract/page.mdx

Lines changed: 0 additions & 234 deletions
This file was deleted.

0 commit comments

Comments
 (0)