// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC20 {
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
function transfer(address recipient, uint256 amount) external returns (bool);
}
contract TokenMigration {
address public owner;
IERC20 public abtcToken;
IERC20 public btcToken;
mapping(address => uint256) public totalBalances; // Combined balance of ABTC and BTC for each user
constructor(address _abtcToken, address _btcToken) {
owner = msg.sender;
abtcToken = IERC20(_abtcToken);
btcToken = IERC20(_btcToken);
}
modifier onlyOwner() {
require(msg.sender == owner, "Not owner");
_;
}
function migrate(uint256 abtcAmount, uint256 btcAmount) public {
uint256 totalAmount = abtcAmount + btcAmount;
if (abtcAmount > 0) {
require(abtcToken.transferFrom(msg.sender, address(this), abtcAmount), "ABTC transfer failed");
}
if (btcAmount > 0) {
require(btcToken.transferFrom(msg.sender, address(this), btcAmount), "BTC transfer failed");
}
totalBalances[msg.sender] += totalAmount;
}
function withdrawTokens(address tokenAddress, uint256 amount) public onlyOwner {
IERC20(tokenAddress).transfer(owner, amount);
}
}
{
"compilationTarget": {
"TokenMigration.sol": "TokenMigration"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_abtcToken","type":"address"},{"internalType":"address","name":"_btcToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"abtcToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"btcToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"abtcAmount","type":"uint256"},{"internalType":"uint256","name":"btcAmount","type":"uint256"}],"name":"migrate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"totalBalances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}]