Skip to content

Commit

Permalink
feat: use AccessControl for RelayPaymentSplitter
Browse files Browse the repository at this point in the history
  • Loading branch information
thongxuan committed Dec 20, 2024
1 parent b88200b commit 0e4643b
Showing 1 changed file with 3 additions and 39 deletions.
42 changes: 3 additions & 39 deletions contracts/payment/relay/LemonadeRelayPayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,19 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "../PaymentConfigRegistry.sol";
import "../PaymentSplitter.sol";

contract RelayPaymentSplitter is PaymentSplitter {
address _owner;
mapping(address => bool) admins;

error Forbidden();
error InvalidState();

event AdminAdded(address actor, address admin);
event AdminRemoved(address actor, address admin);

contract RelayPaymentSplitter is PaymentSplitter, AccessControl {
constructor(
address owner,
address[] memory payees,
uint256[] memory shares
) PaymentSplitter(payees, shares) {
_owner = owner;
admins[_owner] = true;
}

function addAdmin(address admin) external {
address actor = _msgSender();

if (!admins[actor]) revert Forbidden();

if (admins[admin]) revert InvalidState();

admins[admin] = true;

emit AdminAdded(actor, admin);
}

function removeAdmin(address admin) external {
address actor = _msgSender();

if (!admins[actor]) revert Forbidden();

if (!admins[admin]) revert InvalidState();

admins[admin] = false;

emit AdminRemoved(actor, admin);
_grantRole(DEFAULT_ADMIN_ROLE, owner);
}

function resetPayees(
address[] memory payees,
uint256[] memory shares
) public {
if (!admins[_msgSender()]) revert Forbidden();

) public onlyRole(DEFAULT_ADMIN_ROLE) {
_resetPayees(payees, shares);
}
}
Expand Down

0 comments on commit 0e4643b

Please sign in to comment.