-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
301210e
commit 7768fd1
Showing
4 changed files
with
79 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,118 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../../interfaces/IWRON.sol"; | ||
import "../../interfaces/IWRONHelper.sol"; | ||
import "./RONTransferHelper.sol"; | ||
import "./TransferFromHelper.sol"; | ||
import "./TransferHelper.sol"; | ||
import { IWRON } from "../../interfaces/IWRON.sol"; | ||
import { IWRONHelper } from "../../interfaces/IWRONHelper.sol"; | ||
import { RONTransferHelper } from "./RONTransferHelper.sol"; | ||
import { TransferFromHelper } from "./TransferFromHelper.sol"; | ||
import { TransferHelper } from "./TransferHelper.sol"; | ||
|
||
library RONTransferHelperExtended { | ||
/** | ||
* @dev Safely unwraps tokens if it is WRON token and transfers them to a specified recipient. | ||
* @param _wron Address of the WRON contract. | ||
* @param _token Address of the ERC20 token to unwrap and transfer. | ||
* @param _to Address of the recipient to transfer the tokens to. | ||
* @param _amount Amount of tokens to transfer. | ||
* @param wron Address of the WRON contract. | ||
* @param token Address of the ERC20 token to unwrap and transfer. | ||
* @param to Address of the recipient to transfer the tokens to. | ||
* @param amount Amount of tokens to transfer. | ||
* | ||
* Note: This function may cause a revert if the consumer contract is a proxy, consider using the method | ||
* `safeUnwrapTokenAndTransferWithHelper` instead. | ||
*/ | ||
function safeUnwrapTokenAndTransfer(IWRON _wron, address _token, address payable _to, uint256 _amount) internal { | ||
if (_token == address(_wron)) { | ||
function safeUnwrapTokenAndTransfer(IWRON wron, address token, address payable to, uint256 amount) internal { | ||
if (token == address(wron)) { | ||
// Check whether the recipient receives RON | ||
if (RONTransferHelper.send(_to, 0)) { | ||
_wron.withdraw(_amount); | ||
RONTransferHelper.safeTransfer(_to, _amount); | ||
if (RONTransferHelper.send(to, 0)) { | ||
wron.withdraw(amount); | ||
RONTransferHelper.safeTransfer(to, amount); | ||
return; | ||
} | ||
} | ||
|
||
TransferHelper.safeTransfer(_token, _to, _amount); | ||
TransferHelper.safeTransfer(token, to, amount); | ||
} | ||
|
||
/** | ||
* @dev See `safeUnwrapTokenAndTransfer`. | ||
* | ||
* Requirements: | ||
* - The consumer contract must approve the contract `_wronHelper`. | ||
* - The consumer contract must approve the contract `wronHelper`. | ||
* | ||
* Note: This function supports the use of a proxy contract by using the WRONHelper contract to unwrap WRON and | ||
* transfer RON. | ||
*/ | ||
function safeUnwrapTokenAndTransferWithHelper( | ||
IWRON _wron, | ||
IWRONHelper _wronHelper, | ||
address _token, | ||
address payable _to, | ||
uint256 _amount | ||
IWRON wron, | ||
IWRONHelper wronHelper, | ||
address token, | ||
address payable to, | ||
uint256 amount | ||
) internal { | ||
if (_token == address(_wron)) { | ||
if (token == address(wron)) { | ||
// Check whether the recipient receives RON | ||
if (RONTransferHelper.send(_to, 0)) { | ||
_wron.approve(address(_wronHelper), _amount); | ||
_wronHelper.withdrawTo(_to, _amount); | ||
if (RONTransferHelper.send(to, 0)) { | ||
wron.approve(address(wronHelper), amount); | ||
wronHelper.withdrawTo(to, amount); | ||
return; | ||
} | ||
} | ||
|
||
TransferHelper.safeTransfer(_token, _to, _amount); | ||
TransferHelper.safeTransfer(token, to, amount); | ||
} | ||
|
||
/** | ||
* @dev Safely unwraps tokens if it is WRON token from specified sender, and transfers them to a specified recipient. | ||
* @param _wron Address of the WRON contract. | ||
* @param _token Address of the ERC20 token to unwrap and transfer. | ||
* @param _from Address of the sender on whose behalf the tokens will be unwrapped and transferred. | ||
* @param _to Address of the recipient to transfer the tokens to. | ||
* @param _amount Amount of tokens to transfer. | ||
* @param wron Address of the WRON contract. | ||
* @param token Address of the ERC20 token to unwrap and transfer. | ||
* @param from Address of the sender on whose behalf the tokens will be unwrapped and transferred. | ||
* @param to Address of the recipient to transfer the tokens to. | ||
* @param amount Amount of tokens to transfer. | ||
* | ||
* Note: This function may cause a revert if the consumer contract is a proxy, consider using the method | ||
* `safeUnwrapTokenAndTransferFromWithHelper` instead. | ||
*/ | ||
function safeUnwrapTokenAndTransferFrom( | ||
IWRON _wron, | ||
address _token, | ||
address _from, | ||
address payable _to, | ||
uint256 _amount | ||
) internal { | ||
if (_token == address(_wron)) { | ||
function safeUnwrapTokenAndTransferFrom(IWRON wron, address token, address from, address payable to, uint256 amount) | ||
internal | ||
{ | ||
if (token == address(wron)) { | ||
// Check whether the recipient receives RON | ||
if (RONTransferHelper.send(_to, 0)) { | ||
TransferFromHelper.safeTransferFrom(_token, _from, address(this), _amount); | ||
IWRON(_wron).withdraw(_amount); | ||
RONTransferHelper.safeTransfer(_to, _amount); | ||
if (RONTransferHelper.send(to, 0)) { | ||
TransferFromHelper.safeTransferFrom(token, from, address(this), amount); | ||
IWRON(wron).withdraw(amount); | ||
RONTransferHelper.safeTransfer(to, amount); | ||
return; | ||
} | ||
} | ||
|
||
TransferFromHelper.safeTransferFrom(_token, _from, _to, _amount); | ||
TransferFromHelper.safeTransferFrom(token, from, to, amount); | ||
} | ||
|
||
/** | ||
* @dev See `safeUnwrapTokenAndTransfer`. | ||
* | ||
* Requirements: | ||
* - The consumer contract must approve the contract `_wronHelper`. | ||
* - The consumer contract must approve the contract `wronHelper`. | ||
* | ||
* Note: This function supports the use of a proxy contract by using the WRONHelper contract to unwrap WRON and | ||
* transfer RON. | ||
*/ | ||
function safeUnwrapTokenAndTransferFromWithHelper( | ||
IWRON _wron, | ||
IWRONHelper _wronHelper, | ||
address _token, | ||
address _from, | ||
address payable _to, | ||
uint256 _amount | ||
IWRON wron, | ||
IWRONHelper wronHelper, | ||
address token, | ||
address from, | ||
address payable to, | ||
uint256 amount | ||
) internal { | ||
if (_token == address(_wron)) { | ||
if (token == address(wron)) { | ||
// Check whether the recipient receives RON | ||
if (RONTransferHelper.send(_to, 0)) { | ||
TransferFromHelper.safeTransferFrom(_token, _from, address(this), _amount); | ||
_wron.approve(address(_wronHelper), _amount); | ||
_wronHelper.withdrawTo(_to, _amount); | ||
if (RONTransferHelper.send(to, 0)) { | ||
TransferFromHelper.safeTransferFrom(token, from, address(this), amount); | ||
wron.approve(address(wronHelper), amount); | ||
wronHelper.withdrawTo(to, amount); | ||
return; | ||
} | ||
} | ||
|
||
TransferFromHelper.safeTransferFrom(_token, _from, _to, _amount); | ||
TransferFromHelper.safeTransferFrom(token, from, to, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters