diff --git a/contracts/mainnet/connectors/socket/main.sol b/contracts/mainnet/connectors/socket/main.sol index a5b4e223..ba25cbd9 100644 --- a/contracts/mainnet/connectors/socket/main.sol +++ b/contracts/mainnet/connectors/socket/main.sol @@ -12,7 +12,25 @@ import { TokenInterface } from "../../common/interfaces.sol"; import "./events.sol"; import "./interface.sol"; -abstract contract SocketConnectorResolver { +abstract contract SocketConnectorBridge is Basic { + + 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"); + } +} + +abstract contract SocketConnectorResolver is SocketConnectorBridge { /** * @dev Gets Allowance target from registry. @@ -25,15 +43,7 @@ abstract contract SocketConnectorResolver { } } -abstract contract SocketConnector is SocketConnectorResolver, Basic { - - address constant registry = 0xc30141B657f4216252dc59Af2e7CdB9D8792e1B0; - - struct BridgeParams { - bytes txData; - address token; - uint256 amount; - } +abstract contract SocketConnector is SocketConnectorResolver { /** * @dev Bridge Token. @@ -42,44 +52,40 @@ abstract contract SocketConnector is SocketConnectorResolver, Basic { * @param _txData tx data for calling * @param _route route number * @param _amount amount to bridge - * @param _getId ID to retrieve amount from last spell. + * @param _sourceChain Source chain id + * @param _targetChain Source chain id + * @param _recipient address of recipient */ function bridge ( address _token, bytes memory _txData, uint256 _route, uint256 _amount, - uint256 _getId + uint256 _sourceChain, + uint256 _targetChain, + address _recipient ) external payable returns (string memory _eventName, bytes memory _eventParam) { - _amount = getUint(_getId, _amount); + uint _ethAmt; if(_token == ethAddr) { - _amount = _amount == uint256(-1) - ? address(this).balance - : _amount; - - (bool success, ) = registry.call{value: _amount}(_txData); - require(success, "Socket-swap-failed"); + _ethAmt = _amount; } else { TokenInterface _tokenContract = TokenInterface(_token); - _amount = _amount == uint256(-1) - ? _tokenContract.balanceOf(address(this)) - : _amount; - _tokenContract.approve(getAllowanceTarget(_route), _amount); - (bool success, ) = registry.call(_txData); - require(success, "Socket-swap-failed"); } + socketBridge(_txData, _ethAmt); + _eventName = "LogSocketBridge(bytes,address,uint256,uint256)"; _eventParam = abi.encode( - _txData, _token, _amount, - _getId + _sourceChain, + _targetChain, + _recipient ); } } diff --git a/test/mainnet/socket/socket.test.ts b/test/mainnet/socket/socket.test.ts index dde93f84..dc72349c 100644 --- a/test/mainnet/socket/socket.test.ts +++ b/test/mainnet/socket/socket.test.ts @@ -25,7 +25,6 @@ describe("Socket Connector", function () { const fromChainId = "1" const toChainId = "137" - const recipient = "0xD625c7458Da1a0758dA8d3AC7f2c10180Bf0E506" const wallets = provider.getWallets(); const [wallet0, wallet1, wallet2, wallet3] = wallets; @@ -172,7 +171,7 @@ describe("Socket Connector", function () { { connector: connectorName, method: "bridge", - args: [DAI_ADDR_ETH, apiReturnData.result.txData, routeToPass, "1000000000000000000", '0'] + args: [DAI_ADDR_ETH, apiReturnData.result.txData, routeToPass, "1000000000000000000", fromChainId, toChainId, wallet0.address] } ]; @@ -189,7 +188,7 @@ describe("Socket Connector", function () { ETHADDR, toChainId, DAI_ADDR_POLYGON, - "1000000000000000000", + "1000000000000000000", dsaWallet0.address, wallet0.address, "true" @@ -212,7 +211,7 @@ describe("Socket Connector", function () { { connector: connectorName, method: "bridge", - args: [ETHADDR, apiReturnData.result.txData, routeToPass, "1000000000000000000", '0'] + args: [ETHADDR, apiReturnData.result.txData, routeToPass, "1000000000000000000", fromChainId, toChainId, wallet0.address] } ];