-
Notifications
You must be signed in to change notification settings - Fork 5
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
Tasks: Implement Odos swap task #159
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
36863d5
connectors: implement odos connector
PedroAraoz a2556bd
connectors: update bebop fixtures
facuspagnuolo 66d488f
fix base chain tests
PedroAraoz 6deb7c5
tasks: implement odos swap task
PedroAraoz ad66dfa
fix task integration test
PedroAraoz c1a206c
Merge branch 'master' into tasks/implement_odos_swap_task
PedroAraoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/tasks/contracts/interfaces/swap/IOdosV2Swapper.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity >=0.8.0; | ||
|
||
import './IBaseSwapTask.sol'; | ||
|
||
/** | ||
* @dev Odos swapper task interface | ||
*/ | ||
interface IOdosV2Swapper is IBaseSwapTask { | ||
/** | ||
* @dev Execution function | ||
*/ | ||
function call(address tokenIn, uint256 amountIn, uint256 slippage, bytes memory data) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import '@mimic-fi/v3-helpers/contracts/math/FixedPoint.sol'; | ||
import '@mimic-fi/v3-helpers/contracts/utils/BytesHelpers.sol'; | ||
import '@mimic-fi/v3-connectors/contracts/interfaces/odos/IOdosV2Connector.sol'; | ||
|
||
import './BaseSwapTask.sol'; | ||
import '../interfaces/swap/IOdosV2Swapper.sol'; | ||
|
||
/** | ||
* @title Odos v2 swapper | ||
* @dev Task that extends the base swap task to use Odos v2 | ||
*/ | ||
contract OdosV2Swapper is IOdosV2Swapper, BaseSwapTask { | ||
using FixedPoint for uint256; | ||
using BytesHelpers for bytes; | ||
|
||
// Execution type for relayers | ||
bytes32 public constant override EXECUTION_TYPE = keccak256('ODOS_V2_SWAPPER'); | ||
|
||
/** | ||
* @dev Odos v2 swap config. Only used in the initializer. | ||
*/ | ||
struct OdosV2SwapConfig { | ||
BaseSwapConfig baseSwapConfig; | ||
} | ||
|
||
/** | ||
* @dev Initializes the Odos v2 swapper | ||
* @param config Odos v2 swap config | ||
*/ | ||
function initialize(OdosV2SwapConfig memory config) external virtual initializer { | ||
__OdosV2Swapper_init(config); | ||
} | ||
|
||
/** | ||
* @dev Initializes the Odos v2 swapper. It does call upper contracts initializers. | ||
* @param config Odos v2 swap config | ||
*/ | ||
function __OdosV2Swapper_init(OdosV2SwapConfig memory config) internal onlyInitializing { | ||
__BaseSwapTask_init(config.baseSwapConfig); | ||
__OdosV2Swapper_init_unchained(config); | ||
} | ||
|
||
/** | ||
* @dev Initializes the Odos v2 swapper. It does not call upper contracts initializers. | ||
* @param config Odos v2 swap config | ||
*/ | ||
function __OdosV2Swapper_init_unchained(OdosV2SwapConfig memory config) internal onlyInitializing { | ||
// solhint-disable-previous-line no-empty-blocks | ||
} | ||
|
||
/** | ||
* @dev Executes the Odos V2 swapper task | ||
*/ | ||
function call(address tokenIn, uint256 amountIn, uint256 slippage, bytes memory data) | ||
external | ||
override | ||
authP(authParams(tokenIn, amountIn, slippage)) | ||
{ | ||
if (amountIn == 0) amountIn = getTaskAmount(tokenIn); | ||
_beforeOdosV2Swapper(tokenIn, amountIn, slippage); | ||
|
||
address tokenOut = getTokenOut(tokenIn); | ||
uint256 price = _getPrice(tokenIn, tokenOut); | ||
uint256 minAmountOut = amountIn.mulUp(price).mulUp(FixedPoint.ONE - slippage); | ||
bytes memory connectorData = abi.encodeWithSelector( | ||
IOdosV2Connector.execute.selector, | ||
tokenIn, | ||
tokenOut, | ||
amountIn, | ||
minAmountOut, | ||
data | ||
); | ||
|
||
bytes memory result = ISmartVault(smartVault).execute(connector, connectorData); | ||
_afterOdosV2Swapper(tokenIn, amountIn, slippage, tokenOut, result.toUint256()); | ||
} | ||
|
||
/** | ||
* @dev Before Odos v2 swapper hook | ||
*/ | ||
function _beforeOdosV2Swapper(address token, uint256 amount, uint256 slippage) internal virtual { | ||
_beforeBaseSwapTask(token, amount, slippage); | ||
} | ||
|
||
/** | ||
* @dev After Odos v2 swapper hook | ||
*/ | ||
function _afterOdosV2Swapper( | ||
address tokenIn, | ||
uint256 amountIn, | ||
uint256 slippage, | ||
address tokenOut, | ||
uint256 amountOut | ||
) internal virtual { | ||
_afterBaseSwapTask(tokenIn, amountIn, slippage, tokenOut, amountOut); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/tasks/contracts/test/swap/OdosV2ConnectorMock.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
contract OdosV2ConnectorMock { | ||
event LogExecute(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, bytes data); | ||
|
||
function execute(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, bytes memory data) | ||
external | ||
returns (uint256) | ||
{ | ||
emit LogExecute(tokenIn, tokenOut, amountIn, minAmountOut, data); | ||
return minAmountOut; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this path is wrong