-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tasks: Implement socket bridger (#162)
- Loading branch information
1 parent
55a50af
commit ac81ddf
Showing
7 changed files
with
415 additions
and
11 deletions.
There are no files selected for viewing
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,91 @@ | ||
// 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-connectors/contracts/interfaces/socket/ISocketConnector.sol'; | ||
|
||
import './BaseBridgeTask.sol'; | ||
import '../interfaces/bridge/ISocketBridger.sol'; | ||
|
||
/** | ||
* @title Socket bridger | ||
* @dev Task that extends the base bridge task to use Socket | ||
*/ | ||
contract SocketBridger is ISocketBridger, BaseBridgeTask { | ||
using FixedPoint for uint256; | ||
|
||
// Execution type for relayers | ||
bytes32 public constant override EXECUTION_TYPE = keccak256('SOCKET_BRIDGER'); | ||
|
||
/** | ||
* @dev Socket bridge config. Only used in the initializer. | ||
*/ | ||
struct SocketBridgeConfig { | ||
BaseBridgeConfig baseBridgeConfig; | ||
} | ||
|
||
/** | ||
* @dev Initializes the Socket bridger | ||
* @param config Socket bridge config | ||
*/ | ||
function initialize(SocketBridgeConfig memory config) external virtual initializer { | ||
__SocketBridger_init(config); | ||
} | ||
|
||
/** | ||
* @dev Initializes the Socket bridger. It does call upper contracts initializers. | ||
* @param config Socket bridge config | ||
*/ | ||
function __SocketBridger_init(SocketBridgeConfig memory config) internal onlyInitializing { | ||
__BaseBridgeTask_init(config.baseBridgeConfig); | ||
__SocketBridger_init_unchained(config); | ||
} | ||
|
||
/** | ||
* @dev Initializes the Socket bridger. It does not call upper contracts initializers. | ||
* @param config Socket bridge config | ||
*/ | ||
function __SocketBridger_init_unchained(SocketBridgeConfig memory config) internal onlyInitializing { | ||
// solhint-disable-previous-line no-empty-blocks | ||
} | ||
|
||
/** | ||
* @dev Execute Socket bridger | ||
*/ | ||
function call(address token, uint256 amount, bytes memory data) external override authP(authParams(token, amount)) { | ||
if (amount == 0) amount = getTaskAmount(token); | ||
_beforeSocketBridger(token, amount); | ||
|
||
bytes memory connectorData = abi.encodeWithSelector(ISocketConnector.execute.selector, token, amount, data); | ||
ISmartVault(smartVault).execute(connector, connectorData); | ||
_afterSocketBridger(token, amount); | ||
} | ||
|
||
/** | ||
* @dev Before Socket bridger hook | ||
*/ | ||
function _beforeSocketBridger(address token, uint256 amount) internal virtual { | ||
// Socket does not support specifying slippage nor fee | ||
_beforeBaseBridgeTask(token, amount, 0, 0); | ||
} | ||
|
||
/** | ||
* @dev After Socket bridger task hook | ||
*/ | ||
function _afterSocketBridger(address token, uint256 amount) internal virtual { | ||
// Socket does not support specifying slippage nor fee | ||
_afterBaseBridgeTask(token, amount, 0, 0); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/tasks/contracts/interfaces/bridge/ISocketBridger.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 './IBaseBridgeTask.sol'; | ||
|
||
/** | ||
* @dev Socket bridger task interface | ||
*/ | ||
interface ISocketBridger is IBaseBridgeTask { | ||
/** | ||
* @dev Execute Socket bridger task | ||
*/ | ||
function call(address token, uint256 amount, 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
23 changes: 23 additions & 0 deletions
23
packages/tasks/contracts/test/bridge/SocketConnectorMock.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,23 @@ | ||
// 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 SocketConnectorMock { | ||
event LogExecute(address token, uint256 amount, bytes data); | ||
|
||
function execute(address token, uint256 amount, bytes memory data) external { | ||
emit LogExecute(token, amount, data); | ||
} | ||
} |
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.