-
Notifications
You must be signed in to change notification settings - Fork 19
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
Showing
5 changed files
with
136 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
pragma solidity 0.8.18; | ||
|
||
import './interfaces/IWETH.sol'; | ||
|
||
/// @title DePayWETHExchangeV1 | ||
/// @notice This contract limits access to WETH to the functions wrap & unwrap only. | ||
contract DePayWETHExchangeV1 { | ||
|
||
/// @notice Address of WETH | ||
IWETH public immutable WETH; | ||
|
||
/// @dev Initializes the contract with WETH address. | ||
/// @param _WETH The address of the WETH contract. | ||
constructor (address _WETH) { | ||
WETH = IWETH(_WETH); | ||
} | ||
|
||
/// @notice Accepts NATIVE transfers, required for unwrapping. | ||
receive() external payable {} | ||
|
||
/// @notice Deposits native currency and wraps it into WETH. | ||
/// @dev Wraps sent value into WETH and transfers it back to the sender. | ||
/// @return success Status of the deposit operation. | ||
function deposit() external payable returns(bool){ | ||
WETH.deposit{value: msg.value}(); | ||
(bool success) = WETH.transfer(msg.sender, msg.value); | ||
return success; | ||
} | ||
|
||
/// @notice Withdraws specified amount of WETH and unwraps it into native currency. | ||
/// @dev Unwraps WETH into native currency and sends it back to the sender. | ||
/// @param wad Amount of WETH to withdraw. | ||
/// @return success Status of the withdrawal operation. | ||
function withdraw( | ||
uint wad | ||
) external returns(bool){ | ||
WETH.withdraw(wad); | ||
(bool success,) = msg.sender.call{value: wad}(new bytes(0)); | ||
return success; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.18; | ||
|
||
interface IWETH { | ||
|
||
function deposit() payable external; | ||
function transfer(address dst, uint wad) external returns (bool); | ||
function withdraw(uint wad) external; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Dependency file: contracts/interfaces/IWETH.sol | ||
|
||
// SPDX-License-Identifier: MIT | ||
|
||
// pragma solidity 0.8.18; | ||
|
||
interface IWETH { | ||
|
||
function deposit() payable external; | ||
function transfer(address dst, uint wad) external returns (bool); | ||
function withdraw(uint wad) external; | ||
} | ||
|
||
|
||
// Root file: contracts/DePayWETHExchangeV1.sol | ||
|
||
|
||
pragma solidity 0.8.18; | ||
|
||
// import 'contracts/interfaces/IWETH.sol'; | ||
|
||
/// @title DePayWETHExchangeV1 | ||
/// @notice This contract limits access to WETH to the functions wrap & unwrap only. | ||
contract DePayWETHExchangeV1 { | ||
|
||
/// @notice Address of WETH | ||
IWETH public immutable WETH; | ||
|
||
/// @dev Initializes the contract with WETH address. | ||
/// @param _WETH The address of the WETH contract. | ||
constructor (address _WETH) { | ||
WETH = IWETH(_WETH); | ||
} | ||
|
||
/// @notice Accepts NATIVE transfers, required for unwrapping. | ||
receive() external payable {} | ||
|
||
/// @notice Deposits native currency and wraps it into WETH. | ||
/// @dev Wraps sent value into WETH and transfers it back to the sender. | ||
/// @return success Status of the deposit operation. | ||
function deposit() external payable returns(bool){ | ||
WETH.deposit{value: msg.value}(); | ||
(bool success) = WETH.transfer(msg.sender, msg.value); | ||
return success; | ||
} | ||
|
||
/// @notice Withdraws specified amount of WETH and unwraps it into native currency. | ||
/// @dev Unwraps WETH into native currency and sends it back to the sender. | ||
/// @param wad Amount of WETH to withdraw. | ||
/// @return success Status of the withdrawal operation. | ||
function withdraw( | ||
uint wad | ||
) external returns(bool){ | ||
WETH.withdraw(wad); | ||
(bool success,) = msg.sender.call{value: wad}(new bytes(0)); | ||
return success; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Root file: contracts/interfaces/IWETH.sol | ||
|
||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity 0.8.18; | ||
|
||
interface IWETH { | ||
|
||
function deposit() payable external; | ||
function transfer(address dst, uint wad) external returns (bool); | ||
function withdraw(uint wad) external; | ||
} |
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