forked from sushi-labs/sushiswap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish first pass of migration contract
- Loading branch information
Showing
4 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
pragma solidity 0.6.12; | ||
|
||
import "./uniswapv2/interfaces/IUniswapV2ERC20.sol"; | ||
import "./uniswapv2/interfaces/IUniswapV2Pair.sol"; | ||
import "./uniswapv2/interfaces/IUniswapV2Factory.sol"; | ||
|
||
|
||
contract Migrator { | ||
address public chef; | ||
address public factory; | ||
uint256 public notBeforeBlock; | ||
uint256 public desiredLiquidity = uint256(-1); | ||
|
||
constructor(address _chef) public { | ||
constructor(address _chef, address _factory, uint256 _notBeforeBlock) public { | ||
chef = _chef; | ||
factory = _factory; | ||
notBeforeBlock = _notBeforeBlock; | ||
} | ||
|
||
function migrate(address orig) public { | ||
require(msg.sender == chef); | ||
// TODO | ||
function migrate(address orig) public returns (address) { | ||
require(msg.sender == chef, "not the chef"); | ||
require(block.number >= notBeforeBlock, "too early to migrate"); | ||
address token0 = IUniswapV2Pair(orig).token0(); | ||
address token1 = IUniswapV2Pair(orig).token1(); | ||
address pair = IUniswapV2Factory(factory).getPair(token0, token1); | ||
if (pair == address(0)) { | ||
pair = IUniswapV2Factory(factory).createPair(token0, token1); | ||
} | ||
uint256 lp = IUniswapV2ERC20(orig).balanceOf(msg.sender); | ||
if (lp == 0) return pair; | ||
desiredLiquidity = lp; | ||
IUniswapV2ERC20(orig).transferFrom(msg.sender, orig, lp); | ||
IUniswapV2Pair(orig).burn(pair); | ||
IUniswapV2Pair(pair).mint(msg.sender); | ||
desiredLiquidity = uint256(-1); | ||
return pair; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pragma solidity >=0.5.0; | ||
|
||
interface IUniswapV2ERC20 { | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
pragma solidity >=0.5.0; | ||
|
||
interface IUniswapV2Pair { | ||
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; | ||
} |