Skip to content

Commit

Permalink
feat(relay-payment): add admin feature & fix resetPayees issue (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
thongxuan authored Jan 2, 2025
1 parent 5eb4b8c commit 33bddb0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
16 changes: 15 additions & 1 deletion contracts/payment/PaymentSplitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,20 @@ contract PaymentSplitter is Context {
//-- reset total share
_totalShares = 0;

//-- reset shares array
for (uint256 i = 0; i < _payees.length; ) {
address account = _payees[i];
_shares[account] = 0;

unchecked {
++i;
}
}

//-- reset payees array
delete _payees;

for (uint256 i = 0; i < payees.length; i++) {
for (uint256 i = 0; i < payees.length; ) {
address account = payees[i];
uint256 shared = shares_[i];

Expand All @@ -333,6 +343,10 @@ contract PaymentSplitter is Context {
_payees.push(account);
_shares[account] = shared;
_totalShares = _totalShares + shared;

unchecked {
++i;
}
}

emit PayeesReset();
Expand Down
15 changes: 5 additions & 10 deletions contracts/payment/relay/LemonadeRelayPayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "../PaymentConfigRegistry.sol";
import "../PaymentSplitter.sol";

contract RelayPaymentSplitter is PaymentSplitter {
address internal _owner;

error Forbidden();

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

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

) public onlyRole(DEFAULT_ADMIN_ROLE) {
_resetPayees(payees, shares);
}
}
Expand Down Expand Up @@ -128,7 +122,8 @@ contract LemonadeRelayPayment is OwnableUpgradeable {
payable(configRegistry)
);

uint256 transferAmount = amount * 1000000 / (registry.feePPM() + 1000000);
uint256 transferAmount = (amount * 1000000) /
(registry.feePPM() + 1000000);
uint256 feeAmount = amount - transferAmount;

address guest = _msgSender();
Expand Down

0 comments on commit 33bddb0

Please sign in to comment.