Skip to content

Instantly share code, notes, and snippets.

@macalinao
Created February 27, 2021 21:39
Show Gist options
  • Save macalinao/2ca9a77e221643061465df04a1872507 to your computer and use it in GitHub Desktop.
Save macalinao/2ca9a77e221643061465df04a1872507 to your computer and use it in GitHub Desktop.
Ubeswap diff
diff --git a/contracts/uniswapv2/README.md b/contracts/uniswapv2/README.md
index ffa15f4..88cbeba 100644
--- a/contracts/uniswapv2/README.md
+++ b/contracts/uniswapv2/README.md
@@ -1,13 +1,14 @@
# Uniswap V2 Area
-Code from [Uniswap V2](https://github.com/Uniswap/uniswap-v2-core/tree/27f6354bae6685612c182c3bc7577e61bc8717e3/contracts) with the following modifications.
+Code from [Sushiswap](https://github.com/sushiswap/sushiswap/tree/017ac93b1f6e970516652629a4d1bc47a8c584d7/contracts) with the following modifications.
-1. Change contract version to 0.6.12 and do the necessary patching.
-2. Add `migrator` member in `UniswapV2Factory` which can be set by `feeToSetter`.
-3. Allow `migrator` to specify the amount of `liquidity` during the first mint. Disallow first mint if migrator is set.
+1. Remove `migrator` member in `UniswapV2Factory`
+2. Delete references to migrator in UniswapV2Pair.
+3. Delete all UniswapV2Router functions referencing ETH/WETH.
+4. Delete IWETH.
To see all diffs:
```
-$ git diff 4c4bf551417e3df09a25aa0dbb6941cccbbac11a .
-```
\ No newline at end of file
+git diff 017ac93b1f6e970516652629a4d1bc47a8c584d7 .
+```
diff --git a/contracts/uniswapv2/UniswapV2ERC20.sol b/contracts/uniswapv2/UniswapV2ERC20.sol
index 4dbebc2..92b42bc 100644
--- a/contracts/uniswapv2/UniswapV2ERC20.sol
+++ b/contracts/uniswapv2/UniswapV2ERC20.sol
@@ -7,8 +7,8 @@ import './libraries/SafeMath.sol';
contract UniswapV2ERC20 {
using SafeMathUniswap for uint;
- string public constant name = 'SushiSwap LP Token';
- string public constant symbol = 'SLP';
+ string public constant name = 'Ubeswap LP Token';
+ string public constant symbol = 'ULP';
uint8 public constant decimals = 18;
uint public totalSupply;
mapping(address => uint) public balanceOf;
diff --git a/contracts/uniswapv2/UniswapV2Factory.sol b/contracts/uniswapv2/UniswapV2Factory.sol
index 5e1be45..8a4264f 100644
--- a/contracts/uniswapv2/UniswapV2Factory.sol
+++ b/contracts/uniswapv2/UniswapV2Factory.sol
@@ -8,7 +8,6 @@ import './UniswapV2Pair.sol';
contract UniswapV2Factory is IUniswapV2Factory {
address public override feeTo;
address public override feeToSetter;
- address public override migrator;
mapping(address => mapping(address => address)) public override getPair;
address[] public override allPairs;
@@ -49,14 +48,8 @@ contract UniswapV2Factory is IUniswapV2Factory {
feeTo = _feeTo;
}
- function setMigrator(address _migrator) external override {
- require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
- migrator = _migrator;
- }
-
function setFeeToSetter(address _feeToSetter) external override {
require(msg.sender == feeToSetter, 'UniswapV2: FORBIDDEN');
feeToSetter = _feeToSetter;
}
-
}
diff --git a/contracts/uniswapv2/UniswapV2Pair.sol b/contracts/uniswapv2/UniswapV2Pair.sol
index fbd5dcf..f2aefb4 100644
--- a/contracts/uniswapv2/UniswapV2Pair.sol
+++ b/contracts/uniswapv2/UniswapV2Pair.sol
@@ -10,11 +10,6 @@ import './interfaces/IUniswapV2Factory.sol';
import './interfaces/IUniswapV2Callee.sol';
-interface IMigrator {
- // Return the desired amount of liquidity token that the migrator wants.
- function desiredLiquidity() external view returns (uint256);
-}
-
contract UniswapV2Pair is UniswapV2ERC20 {
using SafeMathUniswap for uint;
using UQ112x112 for uint224;
@@ -124,15 +119,8 @@ contract UniswapV2Pair is UniswapV2ERC20 {
bool feeOn = _mintFee(_reserve0, _reserve1);
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
if (_totalSupply == 0) {
- address migrator = IUniswapV2Factory(factory).migrator();
- if (msg.sender == migrator) {
- liquidity = IMigrator(migrator).desiredLiquidity();
- require(liquidity > 0 && liquidity != uint256(-1), "Bad desired liquidity");
- } else {
- require(migrator == address(0), "Must not have migrator");
- liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
- _mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
- }
+ liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
+ _mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
} else {
liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);
}
diff --git a/contracts/uniswapv2/UniswapV2Router02.sol b/contracts/uniswapv2/UniswapV2Router02.sol
index 3aad8f3..db0b1b7 100644
--- a/contracts/uniswapv2/UniswapV2Router02.sol
+++ b/contracts/uniswapv2/UniswapV2Router02.sol
@@ -9,26 +9,19 @@ import './libraries/TransferHelper.sol';
import './interfaces/IUniswapV2Router02.sol';
import './interfaces/IUniswapV2Factory.sol';
import './interfaces/IERC20.sol';
-import './interfaces/IWETH.sol';
contract UniswapV2Router02 is IUniswapV2Router02 {
using SafeMathUniswap for uint;
address public immutable override factory;
- address public immutable override WETH;
modifier ensure(uint deadline) {
require(deadline >= block.timestamp, 'UniswapV2Router: EXPIRED');
_;
}
- constructor(address _factory, address _WETH) public {
+ constructor(address _factory) public {
factory = _factory;
- WETH = _WETH;
- }
-
- receive() external payable {
- assert(msg.sender == WETH); // only accept ETH via fallback from the WETH contract
}
// **** ADD LIQUIDITY ****
@@ -76,30 +69,6 @@ contract UniswapV2Router02 is IUniswapV2Router02 {
TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB);
liquidity = IUniswapV2Pair(pair).mint(to);
}
- function addLiquidityETH(
- address token,
- uint amountTokenDesired,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline
- ) external virtual override payable ensure(deadline) returns (uint amountToken, uint amountETH, uint liquidity) {
- (amountToken, amountETH) = _addLiquidity(
- token,
- WETH,
- amountTokenDesired,
- msg.value,
- amountTokenMin,
- amountETHMin
- );
- address pair = UniswapV2Library.pairFor(factory, token, WETH);
- TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken);
- IWETH(WETH).deposit{value: amountETH}();
- assert(IWETH(WETH).transfer(pair, amountETH));
- liquidity = IUniswapV2Pair(pair).mint(to);
- // refund dust eth, if any
- if (msg.value > amountETH) TransferHelper.safeTransferETH(msg.sender, msg.value - amountETH);
- }
// **** REMOVE LIQUIDITY ****
function removeLiquidity(
@@ -119,27 +88,6 @@ contract UniswapV2Router02 is IUniswapV2Router02 {
require(amountA >= amountAMin, 'UniswapV2Router: INSUFFICIENT_A_AMOUNT');
require(amountB >= amountBMin, 'UniswapV2Router: INSUFFICIENT_B_AMOUNT');
}
- function removeLiquidityETH(
- address token,
- uint liquidity,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline
- ) public virtual override ensure(deadline) returns (uint amountToken, uint amountETH) {
- (amountToken, amountETH) = removeLiquidity(
- token,
- WETH,
- liquidity,
- amountTokenMin,
- amountETHMin,
- address(this),
- deadline
- );
- TransferHelper.safeTransfer(token, to, amountToken);
- IWETH(WETH).withdraw(amountETH);
- TransferHelper.safeTransferETH(to, amountETH);
- }
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
@@ -155,59 +103,6 @@ contract UniswapV2Router02 is IUniswapV2Router02 {
IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);
(amountA, amountB) = removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline);
}
- function removeLiquidityETHWithPermit(
- address token,
- uint liquidity,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline,
- bool approveMax, uint8 v, bytes32 r, bytes32 s
- ) external virtual override returns (uint amountToken, uint amountETH) {
- address pair = UniswapV2Library.pairFor(factory, token, WETH);
- uint value = approveMax ? uint(-1) : liquidity;
- IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);
- (amountToken, amountETH) = removeLiquidityETH(token, liquidity, amountTokenMin, amountETHMin, to, deadline);
- }
-
- // **** REMOVE LIQUIDITY (supporting fee-on-transfer tokens) ****
- function removeLiquidityETHSupportingFeeOnTransferTokens(
- address token,
- uint liquidity,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline
- ) public virtual override ensure(deadline) returns (uint amountETH) {
- (, amountETH) = removeLiquidity(
- token,
- WETH,
- liquidity,
- amountTokenMin,
- amountETHMin,
- address(this),
- deadline
- );
- TransferHelper.safeTransfer(token, to, IERC20Uniswap(token).balanceOf(address(this)));
- IWETH(WETH).withdraw(amountETH);
- TransferHelper.safeTransferETH(to, amountETH);
- }
- function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
- address token,
- uint liquidity,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline,
- bool approveMax, uint8 v, bytes32 r, bytes32 s
- ) external virtual override returns (uint amountETH) {
- address pair = UniswapV2Library.pairFor(factory, token, WETH);
- uint value = approveMax ? uint(-1) : liquidity;
- IUniswapV2Pair(pair).permit(msg.sender, address(this), value, deadline, v, r, s);
- amountETH = removeLiquidityETHSupportingFeeOnTransferTokens(
- token, liquidity, amountTokenMin, amountETHMin, to, deadline
- );
- }
// **** SWAP ****
// requires the initial amount to have already been sent to the first pair
@@ -251,72 +146,6 @@ contract UniswapV2Router02 is IUniswapV2Router02 {
);
_swap(amounts, path, to);
}
- function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
- external
- virtual
- override
- payable
- ensure(deadline)
- returns (uint[] memory amounts)
- {
- require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH');
- amounts = UniswapV2Library.getAmountsOut(factory, msg.value, path);
- require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
- IWETH(WETH).deposit{value: amounts[0]}();
- assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]));
- _swap(amounts, path, to);
- }
- function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
- external
- virtual
- override
- ensure(deadline)
- returns (uint[] memory amounts)
- {
- require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH');
- amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path);
- require(amounts[0] <= amountInMax, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT');
- TransferHelper.safeTransferFrom(
- path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]
- );
- _swap(amounts, path, address(this));
- IWETH(WETH).withdraw(amounts[amounts.length - 1]);
- TransferHelper.safeTransferETH(to, amounts[amounts.length - 1]);
- }
- function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
- external
- virtual
- override
- ensure(deadline)
- returns (uint[] memory amounts)
- {
- require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH');
- amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path);
- require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
- TransferHelper.safeTransferFrom(
- path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]
- );
- _swap(amounts, path, address(this));
- IWETH(WETH).withdraw(amounts[amounts.length - 1]);
- TransferHelper.safeTransferETH(to, amounts[amounts.length - 1]);
- }
- function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
- external
- virtual
- override
- payable
- ensure(deadline)
- returns (uint[] memory amounts)
- {
- require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH');
- amounts = UniswapV2Library.getAmountsIn(factory, amountOut, path);
- require(amounts[0] <= msg.value, 'UniswapV2Router: EXCESSIVE_INPUT_AMOUNT');
- IWETH(WETH).deposit{value: amounts[0]}();
- assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]));
- _swap(amounts, path, to);
- // refund dust eth, if any
- if (msg.value > amounts[0]) TransferHelper.safeTransferETH(msg.sender, msg.value - amounts[0]);
- }
// **** SWAP (supporting fee-on-transfer tokens) ****
// requires the initial amount to have already been sent to the first pair
@@ -355,51 +184,6 @@ contract UniswapV2Router02 is IUniswapV2Router02 {
'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'
);
}
- function swapExactETHForTokensSupportingFeeOnTransferTokens(
- uint amountOutMin,
- address[] calldata path,
- address to,
- uint deadline
- )
- external
- virtual
- override
- payable
- ensure(deadline)
- {
- require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH');
- uint amountIn = msg.value;
- IWETH(WETH).deposit{value: amountIn}();
- assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn));
- uint balanceBefore = IERC20Uniswap(path[path.length - 1]).balanceOf(to);
- _swapSupportingFeeOnTransferTokens(path, to);
- require(
- IERC20Uniswap(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,
- 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'
- );
- }
- function swapExactTokensForETHSupportingFeeOnTransferTokens(
- uint amountIn,
- uint amountOutMin,
- address[] calldata path,
- address to,
- uint deadline
- )
- external
- virtual
- override
- ensure(deadline)
- {
- require(path[path.length - 1] == WETH, 'UniswapV2Router: INVALID_PATH');
- TransferHelper.safeTransferFrom(
- path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amountIn
- );
- _swapSupportingFeeOnTransferTokens(path, address(this));
- uint amountOut = IERC20Uniswap(WETH).balanceOf(address(this));
- require(amountOut >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
- IWETH(WETH).withdraw(amountOut);
- TransferHelper.safeTransferETH(to, amountOut);
- }
// **** LIBRARY FUNCTIONS ****
function quote(uint amountA, uint reserveA, uint reserveB) public pure virtual override returns (uint amountB) {
@@ -445,4 +229,13 @@ contract UniswapV2Router02 is IUniswapV2Router02 {
{
return UniswapV2Library.getAmountsIn(factory, amountOut, path);
}
+
+ function pairFor(address tokenA, address tokenB)
+ public
+ view
+ override
+ returns (address)
+ {
+ return UniswapV2Library.pairFor(factory, tokenA, tokenB);
+ }
}
diff --git a/contracts/uniswapv2/interfaces/IUniswapV2Factory.sol b/contracts/uniswapv2/interfaces/IUniswapV2Factory.sol
index 068250d..02930d7 100644
--- a/contracts/uniswapv2/interfaces/IUniswapV2Factory.sol
+++ b/contracts/uniswapv2/interfaces/IUniswapV2Factory.sol
@@ -7,7 +7,6 @@ interface IUniswapV2Factory {
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);
@@ -17,5 +16,4 @@ interface IUniswapV2Factory {
function setFeeTo(address) external;
function setFeeToSetter(address) external;
- function setMigrator(address) external;
}
diff --git a/contracts/uniswapv2/interfaces/IUniswapV2Router01.sol b/contracts/uniswapv2/interfaces/IUniswapV2Router01.sol
index 0708fef..2e67dcd 100644
--- a/contracts/uniswapv2/interfaces/IUniswapV2Router01.sol
+++ b/contracts/uniswapv2/interfaces/IUniswapV2Router01.sol
@@ -4,7 +4,6 @@ pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
- function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
@@ -16,14 +15,6 @@ interface IUniswapV2Router01 {
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
- function addLiquidityETH(
- address token,
- uint amountTokenDesired,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline
- ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
@@ -33,14 +24,6 @@ interface IUniswapV2Router01 {
address to,
uint deadline
) external returns (uint amountA, uint amountB);
- function removeLiquidityETH(
- address token,
- uint liquidity,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline
- ) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
@@ -51,15 +34,6 @@ interface IUniswapV2Router01 {
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
- function removeLiquidityETHWithPermit(
- address token,
- uint liquidity,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline,
- bool approveMax, uint8 v, bytes32 r, bytes32 s
- ) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
@@ -74,20 +48,6 @@ interface IUniswapV2Router01 {
address to,
uint deadline
) external returns (uint[] memory amounts);
- function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
- external
- payable
- returns (uint[] memory amounts);
- function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
- external
- returns (uint[] memory amounts);
- function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
- external
- returns (uint[] memory amounts);
- function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
- external
- payable
- returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
diff --git a/contracts/uniswapv2/interfaces/IUniswapV2Router02.sol b/contracts/uniswapv2/interfaces/IUniswapV2Router02.sol
index 9ce9d8f..a8b6c50 100644
--- a/contracts/uniswapv2/interfaces/IUniswapV2Router02.sol
+++ b/contracts/uniswapv2/interfaces/IUniswapV2Router02.sol
@@ -5,24 +5,6 @@ pragma solidity >=0.6.2;
import './IUniswapV2Router01.sol';
interface IUniswapV2Router02 is IUniswapV2Router01 {
- function removeLiquidityETHSupportingFeeOnTransferTokens(
- address token,
- uint liquidity,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline
- ) external returns (uint amountETH);
- function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
- address token,
- uint liquidity,
- uint amountTokenMin,
- uint amountETHMin,
- address to,
- uint deadline,
- bool approveMax, uint8 v, bytes32 r, bytes32 s
- ) external returns (uint amountETH);
-
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
@@ -30,17 +12,6 @@ interface IUniswapV2Router02 is IUniswapV2Router01 {
address to,
uint deadline
) external;
- function swapExactETHForTokensSupportingFeeOnTransferTokens(
- uint amountOutMin,
- address[] calldata path,
- address to,
- uint deadline
- ) external payable;
- function swapExactTokensForETHSupportingFeeOnTransferTokens(
- uint amountIn,
- uint amountOutMin,
- address[] calldata path,
- address to,
- uint deadline
- ) external;
+
+ function pairFor(address tokenA, address tokenB) external view returns (address);
}
\ No newline at end of file
diff --git a/contracts/uniswapv2/interfaces/IWETH.sol b/contracts/uniswapv2/interfaces/IWETH.sol
deleted file mode 100644
index f06c35b..0000000
--- a/contracts/uniswapv2/interfaces/IWETH.sol
+++ /dev/null
@@ -1,9 +0,0 @@
-// SPDX-License-Identifier: MIT
-
-pragma solidity >=0.5.0;
-
-interface IWETH {
- function deposit() external payable;
- function transfer(address to, uint value) external returns (bool);
- function withdraw(uint) external;
-}
\ No newline at end of file
diff --git a/contracts/uniswapv2/libraries/UniswapV2Library.sol b/contracts/uniswapv2/libraries/UniswapV2Library.sol
index 66dcc4d..0223edd 100644
--- a/contracts/uniswapv2/libraries/UniswapV2Library.sol
+++ b/contracts/uniswapv2/libraries/UniswapV2Library.sol
@@ -23,7 +23,7 @@ library UniswapV2Library {
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
- hex'e18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303' // init code hash
+ hex'b3b8ff62960acea3a88039ebcf80699f15786f1b17cebd82802f7375827a339c' // init code hash from UniswapV2Factory.pairCodeHash()
))));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment