Skip to content

Update UniswapV2IndexExchangeAdapter to support two-hop trades #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ pragma experimental "ABIEncoderV2";

import { IIndexExchangeAdapter } from "../../../interfaces/IIndexExchangeAdapter.sol";


/**
* @title UniswapV2IndexExchangeAdapter
* @author Set Protocol
*
* A Uniswap Router02 exchange adapter that returns calldata for trading with GeneralIndexModule, allows encoding a trade with a fixed input quantity or
* a fixed output quantity.
*
* CHANGELOG: 7/8/2021
* - Update getTradeCalldata to allow for the intermediate token of the path to be passed in through the _data parameter
*/
contract UniswapV2IndexExchangeAdapter is IIndexExchangeAdapter {

Expand Down Expand Up @@ -65,6 +69,8 @@ contract UniswapV2IndexExchangeAdapter is IIndexExchangeAdapter {
* @param _isSendTokenFixed Boolean indicating if the send quantity is fixed, used to determine correct trade interface
* @param _sourceQuantity Fixed/Max amount of source token to sell
* @param _destinationQuantity Min/Fixed amount of destination token to buy
* @param _data Encoded address intermediary token in the trade path. If empty, path is the input and output tokens.
Note: only allows one intermediary asset
*
* @return address Target contract address
* @return uint256 Call value
Expand All @@ -77,16 +83,26 @@ contract UniswapV2IndexExchangeAdapter is IIndexExchangeAdapter {
bool _isSendTokenFixed,
uint256 _sourceQuantity,
uint256 _destinationQuantity,
bytes memory /*_data*/
bytes memory _data
)
external
view
override
returns (address, uint256, bytes memory)
{
address[] memory path = new address[](2);
path[0] = _sourceToken;
path[1] = _destinationToken;
address[] memory path;

if (_data.length == 0) {
path = new address[](2);
path[0] = _sourceToken;
path[1] = _destinationToken;
} else {
address intermediateToken = abi.decode(_data, (address));
path = new address[](3);
path[0] = _sourceToken;
path[1] = intermediateToken;
path[2] = _destinationToken;
}

bytes memory callData = abi.encodeWithSignature(
_isSendTokenFixed ? SWAP_EXACT_TOKENS_FOR_TOKENS : SWAP_TOKENS_FOR_EXACT_TOKENS,
Expand Down
Loading