Migrator Code
No migrator code
Originally introduced by Chef Nomi in SushiSwap’s MasterChef smart contract, the migrator code allows for a seamless migration of liquidity between different decentralized exchanges. This code can still be found in many forks of Sushiswap including Pancakeswap.
// Set the migrator contract. Can only be called by the owner.
function setMigrator(IMigratorChef _migrator) public onlyOwner {
migrator = _migrator;
// Migrate lp token to another lp contract. Can be called by anyone. We trust that migrator contract is good.
function migrate(uint256 _pid) public {
require(address(migrator) != address(0), "migrate: no migrator");
PoolInfo storage pool = poolInfo[_pid];
IBEP20 lpToken = pool.lpToken;
uint256 bal = lpToken.balanceOf(address(this));
lpToken.safeApprove(address(migrator), bal);
IBEP20 newLpToken = migrator.migrate(lpToken);
require(bal == newLpToken.balanceOf(address(this)), "migrate: bad");
pool.lpToken = newLpToken;
While the migrator code might have been necessary in the early days of DeFi on Ethereum when liquidity vampire was the trend, the risk it poses is too high.
The migrator code can and has been used by some projects as a sinister backdoor to steal users’ assets.
Therefore, the migrator code is not included in the RobustSwap MasterChef’s smart contract.
Copy link