Skip to content

Commit

Permalink
[BOOST-4567] feat(evm): integrate points and pointsincentive auth sch…
Browse files Browse the repository at this point in the history
…emes (#54)
  • Loading branch information
sammccord authored Sep 3, 2024
2 parents e6801e3 + fcc33ae commit b377d63
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/evm/contracts/incentives/APointsIncentive.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Cloneable} from "contracts/shared/Cloneable.sol";

import {Budget} from "contracts/budgets/Budget.sol";
import {Incentive} from "./Incentive.sol";
import {OwnableRoles} from "@solady/auth/OwnableRoles.sol";

/// @title Points Incentive
/// @notice A simple on-chain points incentive implementation that allows claiming of soulbound tokens
Expand All @@ -32,7 +33,13 @@ abstract contract APointsIncentive is Incentive {
/// @notice Claim the incentive
/// @param data_ The data payload for the incentive claim `(address recipient, bytes data)`
/// @return True if the incentive was successfully claimed
function claim(bytes calldata data_) external override onlyOwner returns (bool) {
function claim(bytes calldata data_) external override returns (bool) {
// check ownership
OwnableRoles points = OwnableRoles(venue);
if (points.owner() != msg.sender && points.hasAnyRole(msg.sender, 1 << 1) != true) {
revert BoostError.Unauthorized();
}

ClaimPayload memory claim_ = abi.decode(data_, (ClaimPayload));
if (!_isClaimable(claim_.target)) revert NotClaimable();

Expand Down
9 changes: 9 additions & 0 deletions packages/evm/test/incentives/PointsIncentive.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ contract PointsIncentiveTest is Test {
incentive.claim(abi.encode(Incentive.ClaimPayload({target: address(1), data: new bytes(0)})));
}

function test_claimAuthorized() public {
vm.expectCall(address(points), abi.encodeCall(points.issue, (address(1), 100)), 1);
points.grantRoles(address(0xdeadbeef), points.ISSUER_ROLE());

vm.prank(address(0xdeadbeef));
incentive.claim(abi.encode(Incentive.ClaimPayload({target: address(1), data: new bytes(0)})));
assertEq(points.balanceOf(address(1)), 100);
}

////////////////////////////////////
// PointsIncentive.getComponentInterface //
////////////////////////////////////
Expand Down

0 comments on commit b377d63

Please sign in to comment.