Skip to content

Commit

Permalink
Check old factory
Browse files Browse the repository at this point in the history
  • Loading branch information
chefnomi committed Aug 26, 2020
1 parent c79ae5e commit 6ac37ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions contracts/Migrator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,27 @@ import "./uniswapv2/interfaces/IUniswapV2Factory.sol";

contract Migrator {
address public chef;
address public oldFactory;
IUniswapV2Factory public factory;
uint256 public notBeforeBlock;
uint256 public desiredLiquidity = uint256(-1);

constructor(address _chef, IUniswapV2Factory _factory, uint256 _notBeforeBlock) public {
constructor(
address _chef,
address _oldFactory,
IUniswapV2Factory _factory,
uint256 _notBeforeBlock
) public {
chef = _chef;
oldFactory = _oldFactory;
factory = _factory;
notBeforeBlock = _notBeforeBlock;
}

function migrate(IUniswapV2Pair orig) public returns (IUniswapV2Pair) {
require(msg.sender == chef, "not the chef");
require(msg.sender == chef, "not from master chef");
require(block.number >= notBeforeBlock, "too early to migrate");
require(orig.factory() == oldFactory, "not from old factory");
address token0 = orig.token0();
address token1 = orig.token1();
IUniswapV2Pair pair = IUniswapV2Pair(factory.getPair(token0, token1));
Expand Down
2 changes: 1 addition & 1 deletion test/Migrator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract('Migrator', ([alice, bob, dev, minter]) => {
this.lp1 = await UniswapV2Pair.at((await this.factory1.createPair(this.weth.address, this.token.address)).logs[0].args.pair);
this.lp2 = await UniswapV2Pair.at((await this.factory2.createPair(this.weth.address, this.token.address)).logs[0].args.pair);
this.chef = await MasterChef.new(this.sushi.address, dev, '1000', '0', '100000', { from: alice });
this.migrator = await Migrator.new(this.chef.address, this.factory2.address, '0');
this.migrator = await Migrator.new(this.chef.address, this.factory1.address, this.factory2.address, '0');
await this.sushi.transferOwnership(this.chef.address, { from: alice });
await this.chef.add('100', this.lp1.address, true, { from: alice });
});
Expand Down

0 comments on commit 6ac37ef

Please sign in to comment.