From 5beddb6efb154cf64f6f61737cb171e51739bb26 Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Fri, 3 Jun 2022 18:32:01 +0530 Subject: [PATCH] Socket contracts added --- .../mainnet/connectors/socket/events.sol | 14 ++++ contracts/mainnet/connectors/socket/main.sol | 68 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 contracts/mainnet/connectors/socket/events.sol create mode 100644 contracts/mainnet/connectors/socket/main.sol diff --git a/contracts/mainnet/connectors/socket/events.sol b/contracts/mainnet/connectors/socket/events.sol new file mode 100644 index 00000000..f5196181 --- /dev/null +++ b/contracts/mainnet/connectors/socket/events.sol @@ -0,0 +1,14 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +contract Events { + event LogBridge ( + address to, + bytes txData, + address token, + uint256 allowanceTarget, + uint256 amount, + uint256 getId + ); +} \ No newline at end of file diff --git a/contracts/mainnet/connectors/socket/main.sol b/contracts/mainnet/connectors/socket/main.sol new file mode 100644 index 00000000..797d6c15 --- /dev/null +++ b/contracts/mainnet/connectors/socket/main.sol @@ -0,0 +1,68 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +/** + * @title Socket. + * @dev Multi-chain Bridge Aggregator. + */ + +import { Basic } from "../../common/basic.sol"; +import { TokenInterface } from "../../common/interfaces.sol"; +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; + +abstract contract SocketConnector is Basic { + + struct BridgeParams { + address payable to; + bytes txData; + address token; + address allowanceTarget; + uint256 amount; + } + + function bridge(BridgeParams memory _params, uint256 _getId) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + _params.amount = getUint(_getId, _params.amount); + + if(_params.token == ethAddr) { + _params.amount = _params.amount == uint256(-1) + ? address(this).balance + : _params.amount; + + (bool success, ) = _params.to.call{value: _params.amount}(_params.txData); + require(success); + + } else { + + IERC20 _tokenContract = IERC20(_params.token); + + _params.amount = _params.amount == uint256(-1) + ? _tokenContract.balanceOf(address(this)) + : _params.amount; + + + _tokenContract.approve(_params.allowanceTarget, _params.amount); + (bool success, ) = _params.to.call(_params.txData); + require(success); + } + + _eventName = "LogSocketBridge(address,bytes,address,address,uint256,uint256)"; + _eventParam = abi.encode( + _params.to, + _params.txData, + _params.token, + _params.allowanceTarget, + _params.amount, + _getId + ); + } + +} + +contract ConnectV2Socket is SocketConnector { + string public constant name = "Socket-v1.0"; +}