Skip to content

[FEATURE DONE] add raf token receiver #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/abi/RafTokenReceiver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"type":"constructor","inputs":[{"name":"owner","type":"address","internalType":"address"},{"name":"amount","type":"uint256","internalType":"uint256"}],"stateMutability":"nonpayable"},{"type":"function","name":"deposit","inputs":[],"outputs":[],"stateMutability":"payable"},{"type":"function","name":"deposits","inputs":[{"name":"","type":"address","internalType":"address"}],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"owner","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"requiredAmount","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"setRequiredAmount","inputs":[{"name":"newAmount","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"transferOwnership","inputs":[{"name":"newOwner","type":"address","internalType":"address"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"withdraw","inputs":[{"name":"amount","type":"uint256","internalType":"uint256"}],"outputs":[],"stateMutability":"nonpayable"},{"type":"event","name":"OwnershipTransferred","inputs":[{"name":"user","type":"address","indexed":true,"internalType":"address"},{"name":"newOwner","type":"address","indexed":true,"internalType":"address"}],"anonymous":false},{"type":"event","name":"RafDeposit","inputs":[{"name":"from","type":"address","indexed":false,"internalType":"address"},{"name":"amount","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"RafUpdateRequiredAmount","inputs":[{"name":"amount","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false},{"type":"event","name":"RafWithdraw","inputs":[{"name":"to","type":"address","indexed":false,"internalType":"address"},{"name":"amount","type":"uint256","indexed":false,"internalType":"uint256"}],"anonymous":false}]
1 change: 1 addition & 0 deletions misc/gen_abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const writeAbi = async () => {
"CyberNFTV2.sol/CyberNFTV2.json",
"CyberMintNFTRelayHook.sol/CyberMintNFTRelayHook.json",
"CyberIDPermissionedRelayHook.sol/CyberIDPermissionedRelayHook.json",
"RafTokenReceiver.sol/RafTokenReceiver.json",
];
const ps = folders.map(async (file) => {
const f = await fs.readFile(path.join("./out", file), "utf8");
Expand Down
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;
}
}
Loading