-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE DONE] add raf token receiver
- Loading branch information
1 parent
e948281
commit 12b6059
Showing
1 changed file
with
57 additions
and
0 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,57 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity 0.8.14; | ||
|
||
import { Owned } from "solmate/src/auth/Owned.sol"; | ||
|
||
/** | ||
* @title RafTokenReceiver | ||
* @author CyberConnect | ||
* @notice A contract that receive native token and record the amount. | ||
*/ | ||
contract RafTokenReceiver is Owned { | ||
/*////////////////////////////////////////////////////////////// | ||
STATES | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
mapping(address => uint256) public deposits; | ||
uint256 public requiredAmount; | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
EVENT | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
event RafDeposit(address from, uint256 amount); | ||
event RafWithdraw(address to, uint256 amount); | ||
event RafUpdateRequiredAmount(uint256 amount); | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
CONSTRUCTOR | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
constructor(address owner, uint256 amount) Owned(owner) { | ||
require(amount > 0, "INVALID_AMOUNT"); | ||
requiredAmount = amount; | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
EXTERNAL | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
function deposit() external payable { | ||
require(msg.value == requiredAmount, "WRONG_AMOUNT"); | ||
deposits[msg.sender] += msg.value; | ||
emit RafDeposit(msg.sender, msg.value); | ||
} | ||
|
||
function withdraw(uint256 amount) external onlyOwner { | ||
payable(owner).transfer(amount); | ||
emit RafWithdraw(owner, amount); | ||
} | ||
|
||
function setRequiredAmount(uint256 newAmount) external onlyOwner { | ||
require(newAmount > 0, "INVALID_AMOUNT"); | ||
emit RafUpdateRequiredAmount(newAmount); | ||
requiredAmount = newAmount; | ||
} | ||
} |