|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +/* |
| 3 | + Copyright 2023 ZeroEx Intl. |
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + Unless required by applicable law or agreed to in writing, software |
| 9 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + See the License for the specific language governing permissions and |
| 12 | + limitations under the License. |
| 13 | +*/ |
| 14 | + |
| 15 | +pragma solidity ^0.6.5; |
| 16 | +pragma experimental ABIEncoderV2; |
| 17 | + |
| 18 | +import "@0x/contracts-erc20/src/v06/LibERC20TokenV06.sol"; |
| 19 | +import "@0x/contracts-erc20/src/IERC20Token.sol"; |
| 20 | + |
| 21 | +interface IMaverickV1Router { |
| 22 | + struct ExactInputSingleParams { |
| 23 | + address tokenIn; |
| 24 | + address tokenOut; |
| 25 | + address pool; |
| 26 | + address recipient; |
| 27 | + uint256 deadline; |
| 28 | + uint256 amountIn; |
| 29 | + uint256 amountOutMinimum; |
| 30 | + uint256 sqrtPriceLimitD18; |
| 31 | + } |
| 32 | + |
| 33 | + function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut); |
| 34 | +} |
| 35 | + |
| 36 | +contract MixinMaverickV1 { |
| 37 | + using LibERC20TokenV06 for IERC20Token; |
| 38 | + |
| 39 | + function _tradeMaverickV1( |
| 40 | + IERC20Token sellToken, |
| 41 | + IERC20Token buyToken, |
| 42 | + uint256 sellAmount, |
| 43 | + bytes memory bridgeData |
| 44 | + ) internal returns (uint256 boughtAmount) { |
| 45 | + (IMaverickV1Router router, address pool) = abi.decode(bridgeData, (IMaverickV1Router, address)); |
| 46 | + |
| 47 | + // Grant the MaverickV1 router an allowance to sell the sellToken |
| 48 | + sellToken.approveIfBelow(address(router), sellAmount); |
| 49 | + |
| 50 | + boughtAmount = router.exactInputSingle( |
| 51 | + IMaverickV1Router.ExactInputSingleParams({ |
| 52 | + tokenIn: address(sellToken), |
| 53 | + tokenOut: address(buyToken), |
| 54 | + pool: pool, |
| 55 | + recipient: address(this), |
| 56 | + deadline: block.timestamp, |
| 57 | + amountIn: sellAmount, |
| 58 | + amountOutMinimum: 1, |
| 59 | + sqrtPriceLimitD18: 0 |
| 60 | + }) |
| 61 | + ); |
| 62 | + } |
| 63 | +} |
0 commit comments