Skip to content

Commit

Permalink
Merge pull request #140 from open-format/feature/of-335-anyone-can-re…
Browse files Browse the repository at this point in the history
…ward-from-the-contract

Feature/of 335 anyone can reward from the contract
  • Loading branch information
george-openformat authored Sep 26, 2024
2 parents d4d3c02 + 534de5a commit 6a5b228
Show file tree
Hide file tree
Showing 2 changed files with 346 additions and 48 deletions.
28 changes: 28 additions & 0 deletions src/facet/RewardsFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ contract RewardsFacet is Multicall, SafeOwnable {
bytes32 _activityType,
string calldata _uri
) public {
if (msg.sender != _operator()) {
revert RewardsFacet_NotAuthorized();
}

if (!_canMint(_token)) {
revert RewardsFacet_NotAuthorized();
}
Expand All @@ -68,6 +72,10 @@ contract RewardsFacet is Multicall, SafeOwnable {
bytes32 _activityType,
string calldata _uri
) public {
if (msg.sender != _operator()) {
revert RewardsFacet_NotAuthorized();
}

Token(_token).transferFrom(msg.sender, _to, _amount);
emit TokenTransferred(_token, _to, _amount, _id, _activityType, _uri);
}
Expand All @@ -92,6 +100,10 @@ contract RewardsFacet is Multicall, SafeOwnable {
bytes32 _activityType,
bytes calldata _data
) public {
if (msg.sender != _operator()) {
revert RewardsFacet_NotAuthorized();
}

if (!_canMint(_badgeContract)) {
revert RewardsFacet_NotAuthorized();
}
Expand All @@ -118,6 +130,10 @@ contract RewardsFacet is Multicall, SafeOwnable {
bytes32 _activityType,
bytes calldata _data
) public {
if (msg.sender != _operator()) {
revert RewardsFacet_NotAuthorized();
}

if (!_canMint(_badgeContract)) {
revert RewardsFacet_NotAuthorized();
}
Expand All @@ -135,6 +151,10 @@ contract RewardsFacet is Multicall, SafeOwnable {
bytes32 _activityType,
string calldata _uri
) public {
if (msg.sender != _operator()) {
revert RewardsFacet_NotAuthorized();
}

if (!_canMint(_token)) {
revert RewardsFacet_NotAuthorized();
}
Expand All @@ -150,10 +170,18 @@ contract RewardsFacet is Multicall, SafeOwnable {
bytes32 _activityType,
string calldata _uri
) public {
if (msg.sender != _operator()) {
revert RewardsFacet_NotAuthorized();
}

NFT(_token).transferFrom(msg.sender, _to, _tokenId);
emit BadgeTransferred(_token, _to, _tokenId, _id, _activityType, _uri);
}

function _operator() internal virtual returns (address) {
return _owner();
}

function _canMint(address _token) internal virtual returns (bool) {
return Token(_token).hasRole(ADMIN_ROLE, msg.sender) || Token(_token).hasRole(MINTER_ROLE, msg.sender);
}
Expand Down
Loading

0 comments on commit 6a5b228

Please sign in to comment.