Skip to content

Commit

Permalink
[FEATURE DONE] add raf token receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
mxchencyber committed Dec 2, 2024
1 parent e948281 commit 12b6059
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/periphery/RafTokenReceiver.sol
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;
}
}

0 comments on commit 12b6059

Please sign in to comment.