@@ -20,19 +20,43 @@ import "@0x/contracts-erc20/src/IERC20Token.sol";
2020import "../IBridgeAdapter.sol " ;
2121
2222interface ILBRouter {
23- /// @notice Swaps exact tokens for tokens while performing safety checks
24- /// @param amountIn The amount of token to send
25- /// @param amountOutMin The min amount of token to receive
26- /// @param pairBinSteps The bin step of the pairs (0: V1, other values will use V2)
27- /// @param tokenPath The swap path using the binSteps following `_pairBinSteps`
28- /// @param to The address of the recipient
29- /// @param deadline The deadline of the tx
30- /// @return amountOut Output amount of the swap
23+ /**
24+ * @dev This enum represents the version of the pair requested
25+ * - V1: Joe V1 pair
26+ * - V2: LB pair V2. Also called legacyPair
27+ * - V2_1: LB pair V2.1 (current version)
28+ */
29+ enum Version {
30+ V1,
31+ V2,
32+ V2_1
33+ }
34+
35+ /**
36+ * @dev The path parameters, such as:
37+ * - pairBinSteps: The list of bin steps of the pairs to go through
38+ * - versions: The list of versions of the pairs to go through
39+ * - tokenPath: The list of tokens in the path to go through
40+ */
41+ struct Path {
42+ uint256 [] pairBinSteps;
43+ Version[] versions;
44+ IERC20Token [] tokenPath;
45+ }
46+
47+ /**
48+ * @notice Swaps exact tokens for tokens while performing safety checks
49+ * @param amountIn The amount of token to send
50+ * @param amountOutMin The min amount of token to receive
51+ * @param path The path of the swap
52+ * @param to The address of the recipient
53+ * @param deadline The deadline of the tx
54+ * @return amountOut Output amount of the swap
55+ */
3156 function swapExactTokensForTokens (
3257 uint256 amountIn ,
3358 uint256 amountOutMin ,
34- uint256 [] memory pairBinSteps ,
35- IERC20Token [] memory tokenPath ,
59+ Path memory path ,
3660 address to ,
3761 uint256 deadline
3862 ) external returns (uint256 amountOut );
@@ -49,12 +73,16 @@ contract MixinTraderJoeV2 {
4973 ILBRouter router;
5074 IERC20Token [] memory tokenPath;
5175 uint256 [] memory pairBinSteps;
76+ ILBRouter.Version[] memory versions;
5277 {
53- address [] memory _path;
54- (router, _path, pairBinSteps) = abi.decode (bridgeData, (ILBRouter, address [], uint256 []));
78+ address [] memory _tokenPath;
79+ (router, _tokenPath, pairBinSteps, versions) = abi.decode (
80+ bridgeData,
81+ (ILBRouter, address [], uint256 [], ILBRouter.Version[])
82+ );
5583 // To get around `abi.decode()` not supporting interface array types.
5684 assembly {
57- tokenPath := _path
85+ tokenPath := _tokenPath
5886 }
5987 }
6088
@@ -63,20 +91,22 @@ contract MixinTraderJoeV2 {
6391 tokenPath.length == pairBinSteps.length + 1 ,
6492 "MixinTraderJoeV2/PAIR_BIN_STEPS_LENGTH_MUST_BE_ONE_LESS_THAN_TOKEN_PATH_LENGTH "
6593 );
94+ require (
95+ versions.length == pairBinSteps.length ,
96+ "MixinTraderJoeV2/VERSIONS_LENGTH_MUST_BE_EQUAL_TO_PAIR_BIN_STEPS_LENGTH "
97+ );
6698 require (
6799 tokenPath[tokenPath.length - 1 ] == buyToken,
68100 "MixinTraderJoeV2/LAST_ELEMENT_OF_PATH_MUST_MATCH_OUTPUT_TOKEN "
69101 );
70102 // Grant the Trader Joe V2 router an allowance to sell the first token.
71103 tokenPath[0 ].approveIfBelow (address (router), sellAmount);
72104
73- boughtAmount = router.swapExactTokensForTokens (
74- sellAmount,
75- 1 ,
76- pairBinSteps,
77- tokenPath,
78- address (this ),
79- block .timestamp
80- );
105+ ILBRouter.Path memory path = ILBRouter.Path ({
106+ pairBinSteps: pairBinSteps,
107+ versions: versions,
108+ tokenPath: tokenPath
109+ });
110+ boughtAmount = router.swapExactTokensForTokens (sellAmount, 1 , path, address (this ), block .timestamp );
81111 }
82112}
0 commit comments