_sourceChain assembly + lint

This commit is contained in:
Shriya Tyagi 2022-06-10 23:19:27 +05:30
parent 03941edab3
commit d280a09b64

View File

@ -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 {