@@ -11,8 +11,14 @@ import {UUPSUpgradeable} from "@openzeppelin-upgrades/contracts/proxy/utils/UUPS
1111 * @notice Handles deposits that grant time-limited access to aggregation services.
1212 */
1313contract AggregationModePaymentService is Initializable , OwnableUpgradeable , UUPSUpgradeable {
14- /// @notice for how much time the payment is valid in seconds (86400s = 24hs)
15- uint256 public constant PAYMENT_VALID_UNTIL_SECONDS = 86400 ;
14+ /// @notice for how much time the payment is valid in seconds
15+ uint256 public paymentExpirationTimeSeconds;
16+
17+ /// @notice The amount to pay for a subscription in wei.
18+ uint256 public amountToPayInWei;
19+
20+ /// @notice The address where the payment funds will be sent.
21+ address public paymentFundsRecipient;
1622
1723 /**
1824 * @notice Emitted when a user deposits funds to purchase service time.
@@ -23,7 +29,24 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
2329 */
2430 event UserPayment (address user , uint256 indexed amount , uint256 indexed from , uint256 indexed until );
2531
26- error InvalidDepositAmount (uint256 amount );
32+ /// @notice Event emitted when the payment expiration time is updated
33+ /// @param newExpirationTime the new expiration time in seconds
34+ event PaymentExpirationTimeUpdated (uint256 indexed newExpirationTime );
35+
36+ /// @notice Event emitted when the amount to pay for subscription is updated
37+ /// @param newAmountToPay the new amount to pay for a subscription in wei.
38+ event AmountToPayUpdated (uint256 indexed newAmountToPay );
39+
40+ /// @notice Event emitted when the funds recipient is updated
41+ /// @param newFundsRecipient the new address for receiving the funds on withdrawal.
42+ event FundsRecipientUpdated (address indexed newFundsRecipient );
43+
44+ /// @notice Event emitted when the balance is withdrawn to the recipient address
45+ /// @param recipient the address where the funds will be sent
46+ /// @param amount the amont send to the recipient address
47+ event FundsWithdrawn (address indexed recipient , uint256 amount );
48+
49+ error InvalidDepositAmount (uint256 amountReceived , uint256 amountRequired );
2750
2851 /**
2952 * @notice Disables initializers for the implementation contract.
@@ -36,10 +59,14 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
3659 * @notice Initializes the contract and transfers ownership to the provided address.
3760 * @param _owner Address that becomes the contract owner.
3861 */
39- function initialize (address _owner ) public initializer {
62+ function initialize (address _owner , address _paymentFundsRecipient , uint256 _amountToPayInWei , uint256 _paymentExpirationTimeSeconds ) public initializer {
4063 __Ownable_init ();
4164 __UUPSUpgradeable_init ();
4265 _transferOwnership (_owner);
66+
67+ paymentExpirationTimeSeconds = _paymentExpirationTimeSeconds;
68+ amountToPayInWei = _amountToPayInWei;
69+ paymentFundsRecipient = _paymentFundsRecipient;
4370 }
4471
4572 /**
@@ -52,17 +79,55 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
5279 onlyOwner // solhint-disable-next-line no-empty-blocks
5380 {}
5481
82+ /**
83+ * @notice Sets the new expiration time. Only callable by the owner
84+ * @param newExpirationTimeInSeconds The new expiration time for the users payments in seconds.
85+ */
86+ function setPaymentExpirationTimeSeconds (uint256 newExpirationTimeInSeconds ) public onlyOwner () {
87+ paymentExpirationTimeSeconds = newExpirationTimeInSeconds;
88+
89+ emit PaymentExpirationTimeUpdated (newExpirationTimeInSeconds);
90+ }
91+
92+ /**
93+ * @notice Sets the new amount to pay. Only callable by the owner
94+ * @param newRecipient The new address for receiving the funds on withdrawal.
95+ */
96+ function setFundsRecipientAddress (address newRecipient ) public onlyOwner () {
97+ paymentFundsRecipient = newRecipient;
98+
99+ emit FundsRecipientUpdated (newRecipient);
100+ }
101+
102+ /**
103+ * @notice Sets the new amount to pay. Only callable by the owner
104+ * @param newAmountToPay The new amount to pay for subscription in wei.
105+ */
106+ function setAmountToPay (uint256 newAmountToPay ) public onlyOwner () {
107+ amountToPayInWei = newAmountToPay;
108+
109+ emit AmountToPayUpdated (newAmountToPay);
110+ }
111+
55112 /**
56113 * @notice Accepts payments and validates they meet the minimum requirement.
57114 */
58115 receive () external payable {
59116 uint256 amount = msg .value ;
60117
61- // 1 eth
62- if (amount < 1000000000000000000 ) {
63- revert InvalidDepositAmount (amount);
118+ if (amount < amountToPayInWei) {
119+ revert InvalidDepositAmount (amount, amountToPayInWei);
64120 }
65121
66- emit UserPayment (msg .sender , amount, block .timestamp , block .timestamp + PAYMENT_VALID_UNTIL_SECONDS);
122+ emit UserPayment (msg .sender , amount, block .timestamp , block .timestamp + paymentExpirationTimeSeconds);
123+ }
124+
125+ /**
126+ * @notice Withdraws the contract balance to the recipient address.
127+ */
128+ function withdraw () external onlyOwner {
129+ uint256 balance = address (this ).balance;
130+ payable (paymentFundsRecipient).transfer (balance);
131+ emit FundsWithdrawn (paymentFundsRecipient, balance);
67132 }
68133}
0 commit comments