From d280a09b64bd1919c9c3e342453f6de391af734c Mon Sep 17 00:00:00 2001 From: Shriya Tyagi Date: Fri, 10 Jun 2022 23:19:27 +0530 Subject: [PATCH] _sourceChain assembly + lint --- contracts/mainnet/connectors/socket/main.sol | 119 ++++++++++--------- 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/contracts/mainnet/connectors/socket/main.sol b/contracts/mainnet/connectors/socket/main.sol index 596d4d84..ed0c6f45 100644 --- a/contracts/mainnet/connectors/socket/main.sol +++ b/contracts/mainnet/connectors/socket/main.sol @@ -13,78 +13,87 @@ import "./events.sol"; import "./interface.sol"; abstract contract SocketConnectorBridge is Basic { + address constant registry = 0xc30141B657f4216252dc59Af2e7CdB9D8792e1B0; - address constant registry = 0xc30141B657f4216252dc59Af2e7CdB9D8792e1B0; - - /** - * @dev socket API bridge handler - * @param _txData - contains data returned from socket build-tx API. Struct defined in interfaces.sol - * @param _ethAmt - Eth to bridge for .value() - */ - function socketBridge( - bytes memory _txData, - uint _ethAmt - ) internal returns (bool _success) { - (_success, ) = registry.call{value: _ethAmt}(_txData); - require(_success, "Socket-swap-failed"); - } + /** + * @dev socket API bridge handler + * @param _txData - contains data returned from socket build-tx API. Struct defined in interfaces.sol + * @param _ethAmt - Eth to bridge for .value() + */ + function socketBridge(bytes memory _txData, uint256 _ethAmt) + internal + returns (bool _success) + { + (_success, ) = registry.call{ value: _ethAmt }(_txData); + require(_success, "Socket-swap-failed"); + } } abstract contract SocketConnectorResolver is SocketConnectorBridge { - - /** - * @dev Gets Allowance target from registry. - * @param _route route number - */ - function getAllowanceTarget(uint _route) internal view returns (address _allowanceTarget) { - ISocketRegistry.RouteData memory data = ISocketRegistry(registry).routes(_route); - require(data.route != address(0), "allowanceTarget-not-valid"); - return data.route; - } + /** + * @dev Gets Allowance target from registry. + * @param _route route number + */ + function getAllowanceTarget(uint256 _route) + internal + view + returns (address _allowanceTarget) + { + ISocketRegistry.RouteData memory data = ISocketRegistry(registry) + .routes(_route); + require(data.route != address(0), "allowanceTarget-not-valid"); + return data.route; + } } abstract contract SocketConnector is SocketConnectorResolver { + /** + * @dev Bridge Token. + * @notice Bridge Token on Socket. + * @param _token token address on source chain + * @param _txData tx data for calling + * @param _route route number + * @param _amount amount to bridge + * @param _targetChain Target chain ID + * @param _recipient address of the recipient on the target chain + */ + function bridge( + address _token, + bytes memory _txData, + uint256 _route, + uint256 _amount, + uint256 _targetChain, + address _recipient + ) + external + payable + returns (string memory _eventName, bytes memory _eventParam) + { + uint256 _ethAmt; - /** - * @dev Bridge Token. - * @notice Bridge Token on Socket. - * @param _token token address on source chain - * @param _txData tx data for calling - * @param _route route number - * @param _amount amount to bridge - * @param _targetChain Target chain ID - * @param _recipient address of the recipient on the target chain - */ - function bridge ( - address _token, - bytes memory _txData, - uint256 _route, - uint256 _amount, - uint256 _targetChain, - address _recipient - ) - external payable returns (string memory _eventName, bytes memory _eventParam) - { - uint _ethAmt; + if (_token == ethAddr) { + _ethAmt = _amount; + } else { + TokenInterface _tokenContract = TokenInterface(_token); + _tokenContract.approve(getAllowanceTarget(_route), _amount); + } - if(_token == ethAddr) { - _ethAmt = _amount; - } else { - TokenInterface _tokenContract = TokenInterface(_token); - _tokenContract.approve(getAllowanceTarget(_route), _amount); - } + socketBridge(_txData, _ethAmt); - socketBridge(_txData, _ethAmt); + uint256 _sourceChain; + assembly { + _sourceChain := chainid() + } - _eventName = "LogSocketBridge(address,uint256,uint256,uint256,address)"; + _eventName = "LogSocketBridge(address,uint256,uint256,uint256,address)"; _eventParam = abi.encode( _token, _amount, - block.chainid, + _sourceChain, _targetChain, _recipient ); - } + } } contract ConnectV2Socket is SocketConnector {