diff --git a/contracts/bridge/Controller.sol b/contracts/bridge/Controller.sol index 20187688..c9307c9b 100644 --- a/contracts/bridge/Controller.sol +++ b/contracts/bridge/Controller.sol @@ -27,26 +27,49 @@ contract Controller is Base { address connector_, bytes calldata extraData_, bytes calldata options_ - ) external payable nonReentrant { - ( - TransferInfo memory transferInfo, - bytes memory postHookData - ) = _beforeBridge( - connector_, - TransferInfo(receiver_, amount_, extraData_) - ); + ) public payable nonReentrant { + (TransferInfo memory transferInfo, bytes memory postHookData) = + _beforeBridge(connector_, TransferInfo(receiver_, amount_, extraData_)); // to maintain socket dl specific accounting for super token // re check this logic for mint and mint use cases and if other minter involved totalMinted -= transferInfo.amount; _burn(msg.sender, transferInfo.amount); - _afterBridge( - msgGasLimit_, - connector_, - options_, - postHookData, - transferInfo - ); + _afterBridge(msgGasLimit_, connector_, options_, postHookData, transferInfo); + } + + /** + * @notice Bridges tokens between chains with permit. + * @dev This function allows bridging tokens between different chains. + * @param receiver_ The address to receive the bridged tokens. + * @param amount_ The amount of tokens to bridge. + * @param msgGasLimit_ The gas limit for the execution of the bridging process. + * @param connector_ The address of the connector contract responsible for the bridge. + * @param extraData_ The extra data passed to hook functions. + * @param options_ Additional options for the bridging process. + * @param deadline_ The deadline for the permit signature. + * @param v_ The recovery id of the permit signature. + * @param r_ The r value of the permit signature. + * @param s_ The s value of the permit signature. + */ + function bridgeWithPermit( + address receiver_, + uint256 amount_, + uint256 msgGasLimit_, + address connector_, + bytes calldata execPayload_, + bytes calldata options_, + uint256 deadline_, + uint8 v_, + bytes32 r_, + bytes32 s_ + ) external payable { + + try ERC20(token).permit(msg.sender, address(this), amount_, deadline_, v_, r_, s_) { + bridge(receiver_, amount_, msgGasLimit_, connector_, execPayload_, options_); + } catch { + bridge(receiver_, amount_, msgGasLimit_, connector_, extraData_, options_); + } } /** @@ -55,28 +78,14 @@ contract Controller is Base { * @param siblingChainSlug_ The identifier of the sibling chain. * @param payload_ The payload containing the inbound tokens. */ - function receiveInbound( - uint32 siblingChainSlug_, - bytes memory payload_ - ) external payable override nonReentrant { - ( - address receiver, - uint256 lockAmount, - bytes32 messageId, - bytes memory extraData - ) = abi.decode(payload_, (address, uint256, bytes32, bytes)); + function receiveInbound(uint32 siblingChainSlug_, bytes memory payload_) external payable override nonReentrant { + (address receiver, uint256 lockAmount, bytes32 messageId, bytes memory extraData) = + abi.decode(payload_, (address, uint256, bytes32, bytes)); // convert to shares - TransferInfo memory transferInfo = TransferInfo( - receiver, - lockAmount, - extraData - ); + TransferInfo memory transferInfo = TransferInfo(receiver, lockAmount, extraData); bytes memory postHookData; - (postHookData, transferInfo) = _beforeMint( - siblingChainSlug_, - transferInfo - ); + (postHookData, transferInfo) = _beforeMint(siblingChainSlug_, transferInfo); _mint(transferInfo.receiver, transferInfo.amount); totalMinted += transferInfo.amount; @@ -90,14 +99,8 @@ contract Controller is Base { * @param connector_ The address of the connector contract responsible for the failed transaction. * @param messageId_ The unique identifier of the failed transaction. */ - function retry( - address connector_, - bytes32 messageId_ - ) external nonReentrant { - ( - bytes memory postHookData, - TransferInfo memory transferInfo - ) = _beforeRetry(connector_, messageId_); + function retry(address connector_, bytes32 messageId_) external nonReentrant { + (bytes memory postHookData, TransferInfo memory transferInfo) = _beforeRetry(connector_, messageId_); _mint(transferInfo.receiver, transferInfo.amount); totalMinted += transferInfo.amount; diff --git a/contracts/bridge/Vault.sol b/contracts/bridge/Vault.sol index 696c18cd..0648f20d 100644 --- a/contracts/bridge/Vault.sol +++ b/contracts/bridge/Vault.sol @@ -39,7 +39,7 @@ contract Vault is Base { address connector_, bytes calldata extraData_, bytes calldata options_ - ) external payable nonReentrant { + ) public payable nonReentrant { ( TransferInfo memory transferInfo, bytes memory postHookData @@ -59,6 +59,40 @@ contract Vault is Base { ); } + /** + * @notice Bridges tokens between chains with permit. + * @dev This function allows bridging tokens between different chains. + * @param receiver_ The address to receive the bridged tokens. + * @param amount_ The amount of tokens to bridge. + * @param msgGasLimit_ The gas limit for the execution of the bridging process. + * @param connector_ The address of the connector contract responsible for the bridge. + * @param extraData_ The extra data passed to hook functions. + * @param options_ Additional options for the bridging process. + * @param deadline_ The deadline for the permit signature. + * @param v_ The recovery id of the permit signature. + * @param r_ The r value of the permit signature. + * @param s_ The s value of the permit signature. + */ + function bridgeWithPermit( + address receiver_, + uint256 amount_, + uint256 msgGasLimit_, + address connector_, + bytes calldata execPayload_, + bytes calldata options_, + uint256 deadline_, + uint8 v_, + bytes32 r_, + bytes32 s_ + ) external payable { + + try ERC20(token).permit(msg.sender, address(this), amount_, deadline_, v_, r_, s_) { + bridge(receiver_, amount_, msgGasLimit_, connector_, execPayload_, options_); + } catch { + bridge(receiver_, amount_, msgGasLimit_, connector_, extraData_, options_); + } + } + /** * @notice Receives inbound tokens from another chain. * @dev This function is used to receive tokens from another chain. @@ -112,6 +146,19 @@ contract Vault is Base { _afterRetry(connector_, messageId_, postHookData); } + /** + * @notice Disperse rewards, will be used for dispersing rewards in the future. + * @dev reward token can not be locked token. + * @param receiver_ The address to receive the rewards. + * @param amount_ The amount of rewards to disperse. + * @param rewardToken_ The address of the reward token. + */ + function disperseRewards(address receiver_, uint256 amount_, address rewardToken_) external onlyOwner { + if (rewardToken_ == token) revert("Vault: reward token is same as token"); + ERC20(rewardToken_).safeTransfer(receiver_, amount_); + } + + function _transferTokens(address receiver_, uint256 amount_) internal { if (amount_ == 0) return; if (address(token) == ETH_ADDRESS) {