22pragma solidity ^ 0.8.12 ;
33
44import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol " ;
5- import {OwnableUpgradeable} from "@openzeppelin-upgrades/contracts/access/OwnableUpgradeable.sol " ;
65import {UUPSUpgradeable} from "@openzeppelin-upgrades/contracts/proxy/utils/UUPSUpgradeable.sol " ;
6+ import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol " ;
77
88/**
99 * @title AggregationModePaymentService
1010 * @author Aligned Layer
1111 * @notice Handles deposits that grant time-limited access to aggregation services.
1212 */
13- contract AggregationModePaymentService is Initializable , OwnableUpgradeable , UUPSUpgradeable {
13+ contract AggregationModePaymentService is Initializable , UUPSUpgradeable , AccessControl {
14+
15+ bytes32 public constant OWNER_ROLE = keccak256 ("OWNER_ROLE " );
16+ bytes32 public constant ADMIN_ROLE = keccak256 ("ADMIN_ROLE " );
17+
1418 /// @notice for how much time the payment is valid in seconds
1519 uint256 public paymentExpirationTimeSeconds;
1620
@@ -88,6 +92,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
8892 /**
8993 * @notice Initializes the contract and transfers ownership to the provided address.
9094 * @param _owner Address that becomes the contract owner.
95+ * @param _admin Address that becomes the contract admin.
9196 * @param _paymentFundsRecipient Address that will receive the withdrawal funds.
9297 * @param _amountToPayInWei Amount to pay in wei for the subscription.
9398 * @param _paymentExpirationTimeSeconds The time in seconds that the subscription takes to expire.
@@ -96,15 +101,16 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
96101 */
97102 function initialize (
98103 address _owner ,
104+ address _admin ,
99105 address _paymentFundsRecipient ,
100106 uint256 _amountToPayInWei ,
101107 uint256 _paymentExpirationTimeSeconds ,
102108 uint256 _subscriptionLimit ,
103109 uint256 _maxSubscriptionTimeAhead
104110 ) public initializer {
105- __Ownable_init ();
106111 __UUPSUpgradeable_init ();
107- _transferOwnership (_owner);
112+ _grantRole (OWNER_ROLE, _owner);
113+ _grantRole (ADMIN_ROLE, _admin);
108114
109115 paymentExpirationTimeSeconds = _paymentExpirationTimeSeconds;
110116 amountToPayInWei = _amountToPayInWei;
@@ -120,14 +126,14 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
120126 function _authorizeUpgrade (address newImplementation )
121127 internal
122128 override
123- onlyOwner // solhint-disable-next-line no-empty-blocks
129+ onlyRole (OWNER_ROLE) // solhint-disable-next-line no-empty-blocks
124130 {}
125131
126132 /**
127133 * @notice Sets the new expiration time. Only callable by the owner
128134 * @param newExpirationTimeInSeconds The new expiration time for the users payments in seconds.
129135 */
130- function setPaymentExpirationTimeSeconds (uint256 newExpirationTimeInSeconds ) public onlyOwner ( ) {
136+ function setPaymentExpirationTimeSeconds (uint256 newExpirationTimeInSeconds ) public onlyRole (OWNER_ROLE ) {
131137 paymentExpirationTimeSeconds = newExpirationTimeInSeconds;
132138
133139 emit PaymentExpirationTimeUpdated (newExpirationTimeInSeconds);
@@ -137,7 +143,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
137143 * @notice Sets the new amount to pay. Only callable by the owner
138144 * @param newRecipient The new address for receiving the funds on withdrawal.
139145 */
140- function setFundsRecipientAddress (address newRecipient ) public onlyOwner ( ) {
146+ function setFundsRecipientAddress (address newRecipient ) public onlyRole (OWNER_ROLE ) {
141147 paymentFundsRecipient = newRecipient;
142148
143149 emit FundsRecipientUpdated (newRecipient);
@@ -147,7 +153,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
147153 * @notice Sets the new amount to pay. Only callable by the owner
148154 * @param newAmountToPay The new amount to pay for subscription in wei.
149155 */
150- function setAmountToPay (uint256 newAmountToPay ) public onlyOwner ( ) {
156+ function setAmountToPay (uint256 newAmountToPay ) public onlyRole (OWNER_ROLE ) {
151157 amountToPayInWei = newAmountToPay;
152158
153159 emit AmountToPayUpdated (newAmountToPay);
@@ -157,7 +163,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
157163 * @notice Sets the new subscription limit. Only callable by the owner
158164 * @param newSubscriptionLimit The new monthly subscription limit.
159165 */
160- function setSubscriptionLimit (uint256 newSubscriptionLimit ) public onlyOwner ( ) {
166+ function setSubscriptionLimit (uint256 newSubscriptionLimit ) public onlyRole (OWNER_ROLE ) {
161167 subscriptionLimit = newSubscriptionLimit;
162168
163169 emit SubscriptionLimitUpdated (newSubscriptionLimit);
@@ -167,7 +173,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
167173 * @notice Sets the monthly subscriptions counter to the value received by parameter. Only callable by the owner
168174 * @param newSubscriptionsAmount The new monthly subscription amount.
169175 */
170- function setMonthlySubscriptionsAmount (uint256 newSubscriptionsAmount ) public onlyOwner ( ) {
176+ function setMonthlySubscriptionsAmount (uint256 newSubscriptionsAmount ) public onlyRole (ADMIN_ROLE ) {
171177 monthlySubscriptionsAmount = newSubscriptionsAmount;
172178
173179 emit MonthlySubscriptionsAmountUpdated (newSubscriptionsAmount);
@@ -177,7 +183,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
177183 * @notice Sets the max subscription time ahead to the value received by parameter. Only callable by the owner
178184 * @param newMaxSubscriptionTimeAhead max time allowed to subscribe ahead the current timestamp.
179185 */
180- function setMaxSubscriptionTimeAhead (uint256 newMaxSubscriptionTimeAhead ) public onlyOwner ( ) {
186+ function setMaxSubscriptionTimeAhead (uint256 newMaxSubscriptionTimeAhead ) public onlyRole (OWNER_ROLE ) {
181187 maxSubscriptionTimeAhead = newMaxSubscriptionTimeAhead;
182188
183189 emit MaxSubscriptionTimeAheadUpdated (newMaxSubscriptionTimeAhead);
@@ -188,7 +194,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
188194 * @param addressesToAdd the addresses to be subscribed
189195 * @param expirationTimestamp the expiration timestamp (UTC seconds) for that subscriptions
190196 */
191- function addSubscriptions (address [] memory addressesToAdd , uint256 expirationTimestamp ) public onlyOwner ( ) {
197+ function addSubscriptions (address [] memory addressesToAdd , uint256 expirationTimestamp ) public onlyRole (ADMIN_ROLE ) {
192198 for (uint256 i= 0 ; i < addressesToAdd.length ; ++ i) {
193199 address addressToAdd = addressesToAdd[i];
194200
@@ -230,7 +236,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
230236 /**
231237 * @notice Withdraws the contract balance to the recipient address.
232238 */
233- function withdraw () external onlyOwner {
239+ function withdraw () external onlyRole (OWNER_ROLE) {
234240 uint256 balance = address (this ).balance;
235241 payable (paymentFundsRecipient).transfer (balance);
236242 emit FundsWithdrawn (paymentFundsRecipient, balance);
0 commit comments