文件 1 的 12:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this;
return msg.data;
}
}
文件 2 的 12:DummyToken.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract DummyToken is ERC20("Dummy.Token", "DMT"), Ownable {
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
}
}
文件 3 的 12:ERC20.sol
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor (string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual override returns (string memory) {
return _name;
}
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public virtual override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
return true;
}
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
uint256 senderBalance = _balances[sender];
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
_balances[sender] = senderBalance - amount;
_balances[recipient] += amount;
emit Transfer(sender, recipient, amount);
}
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
}
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
_balances[account] = accountBalance - amount;
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
}
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
文件 4 的 12:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
文件 5 的 12:IERC20Metadata.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 6 的 12:IETacoChef.sol
pragma solidity 0.8.0;
interface IETacoChef {
function poolLength() external view returns (uint256);
function startBlock() external view returns (uint256);
function approveDummies(address) external;
function getrewardForBlock(uint256) external view returns (uint256);
function getReward(uint256, uint256) external view returns (uint256);
function poolInfo(uint256)
external
view
returns (
address,
uint256,
uint256,
uint256
);
function userInfo(uint256, uint256)
external
view
returns (uint256, uint256);
function pendingeTaco(uint256, address) external view returns (uint256);
function speedStake(
uint256,
uint256,
uint256,
uint256,
uint256,
uint256
) external payable returns (uint256);
function totalAllocPoint() external view returns (uint256);
function deposit(uint256, uint256) external;
function setPool(
uint256,
address,
uint256,
uint256,
uint256
) external;
function setUser(
uint256,
address,
uint256,
uint256
) external;
}
文件 7 的 12:IMasterChef.sol
pragma solidity 0.8.0;
interface IMasterChef {
function deposit(uint256, uint256) external;
function harvest(uint256) external;
function poolLength() external returns (uint256);
function userInfo(uint256, address) external returns(uint256, uint256);
function totalAllocPoint() external view returns(uint256);
function pendingTaco() external view returns(uint256);
function poolInfo(uint256) external returns(address, uint256, uint256, uint256);
function setMigrator(address) external;
function migrate(uint256) external;
function massUpdatePools() external;
}
文件 8 的 12:ITacoswapV2Factory.sol
pragma solidity >=0.5.0;
interface ITacoswapV2Factory {
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function migrator() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
function setMigrator(address) external;
}
文件 9 的 12:ITacoswapV2Pair.sol
pragma solidity >=0.5.0;
interface ITacoswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
文件 10 的 12:MigratorDummy.sol
pragma solidity 0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./tacoswapv2/interfaces/ITacoswapV2Pair.sol";
import "./interfaces/IMasterChef.sol";
import "./interfaces/IETacoChef.sol";
import "./DummyToken.sol";
contract MigratorDummy is Ownable {
IMasterChef public oldChef;
IETacoChef public newChef;
uint256 public desiredLiquidity = type(uint256).max;
mapping(address => address) public lpTokenToDummyToken;
mapping(address => bool) public isMigrated;
constructor(
address _oldChef,
address _newChef
) {
require(_oldChef != address(0x0), "Migrator::set zero address");
require(_newChef != address(0x0), "Migrator::set zero address");
oldChef = IMasterChef(_oldChef);
newChef = IETacoChef(_newChef);
}
function migratePools(uint256[] memory oldPools, uint256[] memory newPools) external onlyOwner {
uint256 poolsLength = oldPools.length;
for (uint256 i = 0; i < poolsLength; i++) {
(address lpToken, uint256 allocPoint, uint256 lastRewardBlock, uint256 accTacoPerShare) =
oldChef.poolInfo(oldPools[i]);
ITacoswapV2Pair lp = ITacoswapV2Pair(lpToken);
DummyToken dummyToken = new DummyToken();
dummyToken.mint(address(newChef), lp.balanceOf(address(oldChef)));
dummyToken.mint(msg.sender, 1e21);
lpTokenToDummyToken[lpToken] = address(dummyToken);
newChef.setPool(
newPools[i],
address(dummyToken),
allocPoint,
lastRewardBlock,
accTacoPerShare
);
}
}
function migrateUserInfo() external onlyOwner {
require(!isMigrated[msg.sender], "Migrator: Already migrated");
for (uint256 i = 0; i < 17; i++) {
(uint256 amount, uint256 rewardDebt) = oldChef.userInfo(i, msg.sender);
if (amount == 0) continue;
newChef.setUser(i, msg.sender, amount, rewardDebt);
}
isMigrated[msg.sender] = true;
}
function migrate(ITacoswapV2Pair orig) public onlyOwner returns (IERC20) {
require(
msg.sender == address(oldChef),
"Migrator: not from old master chef"
);
DummyToken dummyToken = new DummyToken();
uint256 lp = orig.balanceOf(msg.sender);
if (lp == 0) return dummyToken;
desiredLiquidity = lp;
orig.transferFrom(msg.sender, address(newChef), lp);
dummyToken.mint(msg.sender, lp);
desiredLiquidity = type(uint256).max;
return dummyToken;
}
}
文件 11 的 12:MigratorFull.sol
pragma solidity 0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./tacoswapv2/interfaces/ITacoswapV2Pair.sol";
import "./tacoswapv2/interfaces/ITacoswapV2Factory.sol";
import "./interfaces/IMasterChef.sol";
import "./interfaces/IETacoChef.sol";
import "./MigratorDummy.sol";
contract MigratorFull {
IMasterChef public oldChef;
IETacoChef public newChef;
MigratorDummy public dummyMigrator;
address public uniFactory;
address public sushiFactory;
ITacoswapV2Factory public factory;
uint256 public desiredLiquidity = type(uint256).max;
IERC20 private _taco;
IERC20 private _etaco;
mapping(address => bool) public isMigrated;
constructor(
address _oldChef,
address _newChef,
address _dummyMigrator,
address _uniFactory,
address _sushiFactory,
address _factory,
address tacoToken_,
address etaco_
) {
require(_oldChef != address(0x0), "Migrator::set zero address");
require(_dummyMigrator != address(0x0), "Migrator::set zero address");
require(_newChef != address(0x0), "Migrator::set zero address");
require(_uniFactory != address(0x0), "Migrator::set zero address");
require(_sushiFactory != address(0x0), "Migrator::set zero address");
require(tacoToken_ != address(0x0), "TacoToETaco::set zero address");
require(etaco_ != address(0x0), "TacoToETaco::set zero address");
_taco = IERC20(tacoToken_);
_etaco = IERC20(etaco_);
uniFactory = _uniFactory;
sushiFactory = _sushiFactory;
oldChef = IMasterChef(_oldChef);
newChef = IETacoChef(_newChef);
dummyMigrator = MigratorDummy(_dummyMigrator);
factory = ITacoswapV2Factory(_factory);
}
function migrate(ITacoswapV2Pair orig) public returns (IERC20) {
require(
msg.sender == address(oldChef),
"Migrator: not from old master chef"
);
uint256 lp = orig.balanceOf(msg.sender);
IERC20 dummyToken = IERC20(dummyMigrator.lpTokenToDummyToken(address(orig)));
newChef.approveDummies(address(dummyToken));
orig.transferFrom(msg.sender, address(newChef), lp);
dummyToken.transferFrom(address(newChef), address(oldChef), lp);
return dummyToken;
}
function migrateLP(ITacoswapV2Pair orig) public returns (ITacoswapV2Pair) {
require(msg.sender == address(newChef), "not from master chef");
require(
orig.factory() == uniFactory || orig.factory() == sushiFactory,
"Migrator: not from old factory"
);
address token0 = orig.token0();
address token1 = orig.token1();
ITacoswapV2Pair pair = ITacoswapV2Pair(factory.getPair(token0, token1));
if (pair == ITacoswapV2Pair(address(0))) {
pair = ITacoswapV2Pair(factory.createPair(token0, token1));
}
uint256 lp = orig.balanceOf(msg.sender);
if (lp == 0) return pair;
desiredLiquidity = lp;
orig.transferFrom(msg.sender, address(orig), lp);
orig.burn(address(pair));
pair.mint(msg.sender);
desiredLiquidity = type(uint256).max;
return pair;
}
function migrateUserInfo() external {
require(!isMigrated[msg.sender], "Migrator: Already migrated");
uint256 oldPoolLength = oldChef.poolLength();
for (uint256 i = 0; i < oldPoolLength; i++) {
(, , , uint256 accTacoPerShare) = oldChef.poolInfo(i);
(uint256 amount, ) = oldChef.userInfo(i, msg.sender);
if (amount == 0) continue;
newChef.setUser(i, msg.sender, amount, amount * accTacoPerShare / 1e12);
}
swap();
isMigrated[msg.sender] = true;
}
function swap() public {
uint256 _amount = _taco.balanceOf(msg.sender);
_taco.transferFrom(msg.sender, address(this), _amount);
_etaco.transfer(msg.sender, _amount);
}
}
文件 12 的 12:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
{
"compilationTarget": {
"cache/solpp-generated-contracts/MigratorFull.sol": "MigratorFull"
},
"evmVersion": "istanbul",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_oldChef","type":"address"},{"internalType":"address","name":"_newChef","type":"address"},{"internalType":"address","name":"_dummyMigrator","type":"address"},{"internalType":"address","name":"_uniFactory","type":"address"},{"internalType":"address","name":"_sushiFactory","type":"address"},{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"tacoToken_","type":"address"},{"internalType":"address","name":"etaco_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"desiredLiquidity","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dummyMigrator","outputs":[{"internalType":"contract MigratorDummy","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract ITacoswapV2Factory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isMigrated","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ITacoswapV2Pair","name":"orig","type":"address"}],"name":"migrate","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ITacoswapV2Pair","name":"orig","type":"address"}],"name":"migrateLP","outputs":[{"internalType":"contract ITacoswapV2Pair","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"migrateUserInfo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"newChef","outputs":[{"internalType":"contract IETacoChef","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oldChef","outputs":[{"internalType":"contract IMasterChef","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sushiFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"uniFactory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]