fix: CryptoCom rollup (#98)

This commit is contained in:
Jacob Evans
2020-12-23 10:43:11 +10:00
committed by GitHub
parent 12ba4c373a
commit 5befb87071
3 changed files with 16 additions and 20 deletions

View File

@@ -1,4 +1,12 @@
[ [
{
"version": "0.16.0",
"changes": [
{
"note": "Fix CryptoCom rollup"
}
]
},
{ {
"version": "0.15.0", "version": "0.15.0",
"changes": [ "changes": [

View File

@@ -95,7 +95,7 @@ contract BridgeAdapter is
MixinBancor(addresses) MixinBancor(addresses)
MixinCoFiX() MixinCoFiX()
MixinCurve() MixinCurve()
MixinCryptoCom(addresses) MixinCryptoCom()
MixinDodo(addresses) MixinDodo(addresses)
MixinKyber(addresses) MixinKyber(addresses)
MixinMooniswap(addresses) MixinMooniswap(addresses)

View File

@@ -22,23 +22,12 @@ pragma experimental ABIEncoderV2;
import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol"; import "@0x/contracts-erc20/contracts/src/v06/LibERC20TokenV06.sol";
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol"; import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
import "./MixinAdapterAddresses.sol";
import "./MixinUniswapV2.sol"; import "./MixinUniswapV2.sol";
contract MixinCryptoCom is contract MixinCryptoCom
MixinAdapterAddresses
{ {
using LibERC20TokenV06 for IERC20TokenV06; using LibERC20TokenV06 for IERC20TokenV06;
/// @dev Mainnet address of the `CryptoComRouter` contract.
IUniswapV2Router02 private immutable CRYPTOCOM_ROUTER;
constructor(AdapterAddresses memory addresses)
public
{
CRYPTOCOM_ROUTER = IUniswapV2Router02(addresses.cryptoComBridge);
}
function _tradeCryptoCom( function _tradeCryptoCom(
IERC20TokenV06 buyToken, IERC20TokenV06 buyToken,
uint256 sellAmount, uint256 sellAmount,
@@ -48,7 +37,9 @@ contract MixinCryptoCom is
returns (uint256 boughtAmount) returns (uint256 boughtAmount)
{ {
// solhint-disable indent // solhint-disable indent
address[] memory path = abi.decode(bridgeData, (address[])); address[] memory path;
address router;
(path, router) = abi.decode(bridgeData, (address[], address));
// solhint-enable indent // solhint-enable indent
require(path.length >= 2, "CryptoComBridge/PATH_LENGTH_MUST_BE_AT_LEAST_TWO"); require(path.length >= 2, "CryptoComBridge/PATH_LENGTH_MUST_BE_AT_LEAST_TWO");
@@ -56,13 +47,10 @@ contract MixinCryptoCom is
path[path.length - 1] == address(buyToken), path[path.length - 1] == address(buyToken),
"CryptoComBridge/LAST_ELEMENT_OF_PATH_MUST_MATCH_OUTPUT_TOKEN" "CryptoComBridge/LAST_ELEMENT_OF_PATH_MUST_MATCH_OUTPUT_TOKEN"
); );
// Grant the Uniswap router an allowance to sell the first token. // Grant the CryptoCom router an allowance to sell the first token.
IERC20TokenV06(path[0]).approveIfBelow( IERC20TokenV06(path[0]).approveIfBelow(router, sellAmount);
address(CRYPTOCOM_ROUTER),
sellAmount
);
uint[] memory amounts = CRYPTOCOM_ROUTER.swapExactTokensForTokens( uint[] memory amounts = IUniswapV2Router02(router).swapExactTokensForTokens(
// Sell all tokens we hold. // Sell all tokens we hold.
sellAmount, sellAmount,
// Minimum buy amount. // Minimum buy amount.