Skip to content

Commit

Permalink
Feat: Remove ERC1155 Claim reward token
Browse files Browse the repository at this point in the history
  • Loading branch information
vasinl124 committed Oct 10, 2024
1 parent db91aaa commit 4ad3f21
Showing 1 changed file with 14 additions and 54 deletions.
68 changes: 14 additions & 54 deletions contracts/soulbounds/RewardsNative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

import { AdminERC1155Soulbound } from "../soulbounds/AdminERC1155Soulbound.sol";
import { ERCWhitelistSignature } from "../ercs/ERCWhitelistSignature.sol";
import { LibRewards } from "../libraries/LibRewards.sol";

Expand Down Expand Up @@ -57,8 +56,6 @@ contract Rewards is
bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");
bytes32 public constant DEV_CONFIG_ROLE = keccak256("DEV_CONFIG_ROLE");

AdminERC1155Soulbound private rewardTokenContract;

uint256[] public itemIds;
mapping(uint256 => bool) private tokenExists;
mapping(uint256 => LibRewards.RewardToken) public tokenRewards;
Expand All @@ -67,7 +64,6 @@ contract Rewards is
mapping(uint256 => uint256) public currentRewardSupply; // rewardTokenId => currentRewardSupply

event TokenAdded(uint256 indexed tokenId);
event Minted(address indexed to, uint256 indexed tokenId, uint256 amount, bool soulbound);
event Claimed(address indexed to, uint256 indexed tokenId, uint256 amount);

constructor(address devWallet) {
Expand All @@ -81,34 +77,23 @@ contract Rewards is
address _devWallet,
address _adminWallet,
address _managerWallet,
address _minterWallet,
address _rewardTokenAddress
address _minterWallet
) external initializer onlyRole(DEFAULT_ADMIN_ROLE) {
if (
_devWallet == address(0) ||
_managerWallet == address(0) ||
_minterWallet == address(0) ||
_rewardTokenAddress == address(0)
) {
revert AddressIsZero();
}

rewardTokenContract = AdminERC1155Soulbound(_rewardTokenAddress);
_grantRole(DEFAULT_ADMIN_ROLE, _adminWallet);
_grantRole(DEV_CONFIG_ROLE, _devWallet);
_grantRole(MANAGER_ROLE, _managerWallet);
_grantRole(MINTER_ROLE, _minterWallet);
_addWhitelistSigner(_devWallet);
}

function updateRewardTokenContract(address _rewardTokenAddress) external onlyRole(DEV_CONFIG_ROLE) {
if (_rewardTokenAddress == address(0)) {
revert AddressIsZero();
}

rewardTokenContract = AdminERC1155Soulbound(_rewardTokenAddress);
}

function isTokenExist(uint256 _tokenId) public view returns (bool) {
if (!tokenExists[_tokenId]) {
return false;
Expand Down Expand Up @@ -168,7 +153,6 @@ contract Rewards is
tokenRewards[_token.tokenId] = _token;
tokenExists[_token.tokenId] = true;
itemIds.push(_token.tokenId);
rewardTokenContract.addNewToken(_token.tokenId);

emit TokenAdded(_token.tokenId);
}
Expand Down Expand Up @@ -257,14 +241,6 @@ contract Rewards is
revert AddressIsZero();
}

// check if the user has the reward token to redeem or not
if (rewardTokenContract.balanceOf(_to, _rewardTokenId) == 0) {
revert InsufficientBalance();
}

// then burn the reward token
rewardTokenContract.whitelistBurn(_to, _rewardTokenId, 1);

_distributeReward(_to, _rewardTokenId);
}

Expand All @@ -283,21 +259,17 @@ contract Rewards is
function _mintAndClaimRewardTokenBatch(
address to,
uint256[] memory _tokenIds,
uint256 _amount,
bool soulbound,
bool isClaimReward
uint256 _amount
) private {
for (uint256 i = 0; i < _tokenIds.length; i++) {
_mintAndClaimRewardToken(to, _tokenIds[i], _amount, soulbound, isClaimReward);
_mintAndClaimRewardToken(to, _tokenIds[i], _amount);
}
}

function _mintAndClaimRewardToken(
address to,
uint256 _tokenId,
uint256 _amount,
bool soulbound,
bool isClaimReward
uint256 _amount
) private {
if (to == address(0)) {
revert AddressIsZero();
Expand All @@ -323,14 +295,8 @@ contract Rewards is
}

// claim the reward
if (isClaimReward) {
for (uint256 i = 0; i < _amount; i++) {
_distributeReward(to, _tokenId);
}
} else {
// mint reward token
rewardTokenContract.adminMintId(to, _tokenId, _amount, soulbound);
emit Minted(to, _tokenId, _amount, soulbound);
for (uint256 i = 0; i < _amount; i++) {
_distributeReward(to, _tokenId);
}
}

Expand Down Expand Up @@ -368,46 +334,40 @@ contract Rewards is

function mint(
bytes calldata data,
bool isSoulbound,
uint256 nonce,
bytes calldata signature,
bool isClaimReward
bytes calldata signature
) external nonReentrant signatureCheck(_msgSender(), nonce, data, signature) whenNotPaused {
uint256[] memory _tokenIds = _verifyContractChainIdAndDecode(data);
_mintAndClaimRewardTokenBatch(_msgSender(), _tokenIds, 1, isSoulbound, isClaimReward);
_mintAndClaimRewardTokenBatch(_msgSender(), _tokenIds, 1);
}

function adminMint(
address to,
bytes calldata data,
bool isSoulbound,
bool isClaimReward
bytes calldata data
) external onlyRole(MINTER_ROLE) whenNotPaused {
uint256[] memory _tokenIds = _verifyContractChainIdAndDecode(data);
_mintAndClaimRewardTokenBatch(to, _tokenIds, 1, isSoulbound, isClaimReward);
_mintAndClaimRewardTokenBatch(to, _tokenIds, 1);
}

function adminMintById(
address toAddress,
uint256 _tokenId,
uint256 _amount,
bool isSoulbound
uint256 _amount
) public onlyRole(MINTER_ROLE) whenNotPaused {
_mintAndClaimRewardToken(toAddress, _tokenId, _amount, isSoulbound, false);
_mintAndClaimRewardToken(toAddress, _tokenId, _amount);
}

function adminBatchMintById(
address[] calldata toAddresses,
uint256 _tokenId,
uint256[] calldata _amounts,
bool isSoulbound
uint256[] calldata _amounts
) public onlyRole(MINTER_ROLE) whenNotPaused {
if (toAddresses.length != _amounts.length) {
revert InvalidLength();
}

for (uint256 i = 0; i < toAddresses.length; i++) {
_mintAndClaimRewardToken(toAddresses[i], _tokenId, _amounts[i], isSoulbound, false);
_mintAndClaimRewardToken(toAddresses[i], _tokenId, _amounts[i]);
}
}

Expand Down

0 comments on commit 4ad3f21

Please sign in to comment.