@0x/asset-swapper: special case BNB in uni v1 sampler (#147)

Co-authored-by: Lawrence Forman <me@merklejerk.com>
This commit is contained in:
Lawrence Forman
2021-02-19 01:56:16 -05:00
committed by GitHub
parent 076f263a86
commit 297342092b
2 changed files with 14 additions and 0 deletions

View File

@@ -25,6 +25,10 @@
{
"note": "Fix protocol fee in fee schedule for `RfqOrder`",
"pr": 146
},
{
"note": "Special case BNB in uni v1 sampler",
"pr": 147
}
]
},

View File

@@ -42,6 +42,8 @@ contract UniswapSampler is
{
/// @dev Gas limit for Uniswap calls.
uint256 constant private UNISWAP_CALL_GAS = 150e3; // 150k
// @dev The BNB token is poisoned on uniswap v1.
address constant private BAD_MAKER_TOKEN = 0xB8c77482e45F1F44dE1745F52C74426C631bDD52;
/// @dev Sample sell quotes from Uniswap.
/// @param takerToken Address of the taker token (what to sell).
@@ -61,6 +63,10 @@ contract UniswapSampler is
_assertValidPair(makerToken, takerToken);
uint256 numSamples = takerTokenAmounts.length;
makerTokenAmounts = new uint256[](numSamples);
if (makerToken == BAD_MAKER_TOKEN) {
// BNB is poisoned on v1. You can only sell to it.
return makerTokenAmounts;
}
IUniswapExchangeQuotes takerTokenExchange = takerToken == _getWethAddress() ?
IUniswapExchangeQuotes(0) : _getUniswapExchange(takerToken);
IUniswapExchangeQuotes makerTokenExchange = makerToken == _getWethAddress() ?
@@ -120,6 +126,10 @@ contract UniswapSampler is
_assertValidPair(makerToken, takerToken);
uint256 numSamples = makerTokenAmounts.length;
takerTokenAmounts = new uint256[](numSamples);
if (makerToken == BAD_MAKER_TOKEN) {
// BNB is poisoned on v1. You can only sell to it.
return takerTokenAmounts;
}
IUniswapExchangeQuotes takerTokenExchange = takerToken == _getWethAddress() ?
IUniswapExchangeQuotes(0) : _getUniswapExchange(takerToken);
IUniswapExchangeQuotes makerTokenExchange = makerToken == _getWethAddress() ?