forked from Orbis86org/Launchez
-
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
Showing
1 changed file
with
41 additions
and
55 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 |
---|---|---|
@@ -1,78 +1,64 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
//Burner Contract. The tokens are sent here before the deployment on SaucerSwap. | ||
|
||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import "@hashgraph/sdk/contracts/hts-precompile/HederaTokenService.sol"; | ||
import "@hashgraph/sdk/contracts/hts-precompile/IHederaTokenService.sol"; | ||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract Burn is ReentrancyGuard, Ownable { | ||
mapping(address => uint256) private tokenBalances; | ||
bool public paused; | ||
contract HederaBurnerContract is HederaTokenService { | ||
address public immutable owner; | ||
mapping(address => int64) private tokenBalances; | ||
address[] private tokenList; | ||
|
||
event TokenReceived(address indexed token, uint256 amount); | ||
event TokensWithdrawn(address indexed token, uint256 amount); | ||
event ContractPaused(); | ||
event ContractUnpaused(); | ||
event TokenReceived(address indexed token, int64 amount); | ||
|
||
modifier whenNotPaused() { | ||
require(!paused, "Contract is paused"); | ||
_; | ||
constructor() { | ||
owner = msg.sender; | ||
} | ||
|
||
constructor() Ownable() { | ||
paused = false; // Initialize as not paused | ||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Not authorized"); | ||
_; | ||
} | ||
|
||
function receiveToken(address token, uint256 amount) external nonReentrant whenNotPaused { | ||
require(amount > 0, "Amount must be greater than 0"); | ||
require(token != address(0), "Invalid token address"); | ||
function receiveToken(address _token, int64 _amount) external onlyOwner { | ||
require(_token != address(0), "Invalid token address"); | ||
require(_amount > 0, "Amount must be greater than 0"); | ||
|
||
int64 balanceBefore = HederaTokenService.getTokenBalance(token, address(this)); | ||
(int responseCode) = HederaTokenService.transferToken(token, msg.sender, address(this), int64(amount)); | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Token transfer failed"); | ||
int64 balanceBefore = getTokenBalance(_token); | ||
|
||
(int responseCode, ) = HederaTokenService.associateToken(address(this), _token); | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Token association failed"); | ||
|
||
int64 balanceAfter = HederaTokenService.getTokenBalance(token, address(this)); | ||
uint256 actualAmount = uint256(balanceAfter - balanceBefore); | ||
tokenBalances[token] += actualAmount; | ||
(responseCode) = HederaTokenService.transferToken(_token, msg.sender, address(this), _amount); | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Token transfer failed"); | ||
|
||
emit TokenReceived(token, actualAmount); | ||
} | ||
int64 balanceAfter = getTokenBalance(_token); | ||
int64 actualAmount = balanceAfter - balanceBefore; | ||
|
||
function receiveTokens(address[] calldata tokens, uint256[] calldata amounts) external nonReentrant whenNotPaused { | ||
require(tokens.length == amounts.length, "Tokens and amounts length mismatch"); | ||
for (uint256 i = 0; i < tokens.length; i++) { | ||
receiveToken(tokens[i], amounts[i]); | ||
if (tokenBalances[_token] == 0) { | ||
tokenList.push(_token); | ||
} | ||
} | ||
|
||
function withdrawToken(address token, uint256 amount) external nonReentrant onlyOwner { | ||
require(amount > 0, "Amount must be greater than 0"); | ||
require(tokenBalances[token] >= amount, "Insufficient balance"); | ||
require(token != address(0), "Invalid token address"); | ||
tokenBalances[_token] += actualAmount; | ||
|
||
int64 balanceBefore = HederaTokenService.getTokenBalance(token, address(this)); | ||
(int responseCode) = HederaTokenService.transferToken(token, address(this), msg.sender, int64(amount)); | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Token transfer failed"); | ||
|
||
int64 balanceAfter = HederaTokenService.getTokenBalance(token, address(this)); | ||
uint256 actualAmount = uint256(balanceBefore - balanceAfter); | ||
tokenBalances[token] -= actualAmount; | ||
emit TokenReceived(_token, actualAmount); | ||
} | ||
|
||
emit TokensWithdrawn(token, actualAmount); | ||
function getTokenList() external view returns (address[] memory) { | ||
return tokenList; | ||
} | ||
|
||
function pauseContract() external onlyOwner { | ||
paused = true; | ||
emit ContractPaused(); | ||
function getTokenBalance(address _token) public view returns (int64) { | ||
(int responseCode, uint256 balance, , ) = HederaTokenService.getTokenInfo(_token); | ||
require(responseCode == HederaResponseCodes.SUCCESS, "Failed to get token info"); | ||
return int64(uint64(balance)); | ||
} | ||
|
||
function unpauseContract() external onlyOwner { | ||
paused = false; | ||
emit ContractUnpaused(); | ||
receive() external payable { | ||
revert("This contract does not accept HBAR"); | ||
} | ||
|
||
function getTokenBalance(address token) external view returns (uint256) { | ||
return tokenBalances[token]; | ||
fallback() external payable { | ||
revert("This contract does not accept HBAR"); | ||
} | ||
} | ||
} |