Skip to content

Commit 7e899d7

Browse files
ncitronrichardliang
authored andcommitted
Update UniswapV2IndexExchangeAdapter to support two-hop trades (#110)
* update adapter and tests * add integration test * improve comments * review changes
1 parent 259653e commit 7e899d7

File tree

3 files changed

+445
-6
lines changed

3 files changed

+445
-6
lines changed

contracts/protocol/integration/index-exchange/UniswapV2IndexExchangeAdapter.sol

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ pragma experimental "ABIEncoderV2";
2121

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

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

@@ -65,6 +69,8 @@ contract UniswapV2IndexExchangeAdapter is IIndexExchangeAdapter {
6569
* @param _isSendTokenFixed Boolean indicating if the send quantity is fixed, used to determine correct trade interface
6670
* @param _sourceQuantity Fixed/Max amount of source token to sell
6771
* @param _destinationQuantity Min/Fixed amount of destination token to buy
72+
* @param _data Encoded address intermediary token in the trade path. If empty, path is the input and output tokens.
73+
Note: only allows one intermediary asset
6874
*
6975
* @return address Target contract address
7076
* @return uint256 Call value
@@ -77,16 +83,26 @@ contract UniswapV2IndexExchangeAdapter is IIndexExchangeAdapter {
7783
bool _isSendTokenFixed,
7884
uint256 _sourceQuantity,
7985
uint256 _destinationQuantity,
80-
bytes memory /*_data*/
86+
bytes memory _data
8187
)
8288
external
8389
view
8490
override
8591
returns (address, uint256, bytes memory)
8692
{
87-
address[] memory path = new address[](2);
88-
path[0] = _sourceToken;
89-
path[1] = _destinationToken;
93+
address[] memory path;
94+
95+
if (_data.length == 0) {
96+
path = new address[](2);
97+
path[0] = _sourceToken;
98+
path[1] = _destinationToken;
99+
} else {
100+
address intermediateToken = abi.decode(_data, (address));
101+
path = new address[](3);
102+
path[0] = _sourceToken;
103+
path[1] = intermediateToken;
104+
path[2] = _destinationToken;
105+
}
90106

91107
bytes memory callData = abi.encodeWithSignature(
92108
_isSendTokenFixed ? SWAP_EXACT_TOKENS_FOR_TOKENS : SWAP_TOKENS_FOR_EXACT_TOKENS,

0 commit comments

Comments
 (0)