Skip to content

Commit 42a7330

Browse files
Add attribute, setter and event for the amount to pay in wei
1 parent b3079f4 commit 42a7330

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

contracts/src/core/AggregationModePaymentService.sol

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
1717
/// @notice for how much time the payment is valid in seconds
1818
uint256 public paymentExpirationTimeSeconds;
1919

20+
/// @notice The amount to pay for a subscription in wei.
21+
uint256 public amountToPayInWei;
22+
2023
/**
2124
* @notice Emitted when a user deposits funds to purchase service time.
2225
* @param user Address that sent the payment.
@@ -30,7 +33,11 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
3033
/// @param newExpirationTime the new expiration time in seconds
3134
event PaymentExpirationTimeUpdated(uint256 indexed newExpirationTime);
3235

33-
error InvalidDepositAmount(uint256 amount);
36+
/// @notice Event emitted when the payment expiration time is updated
37+
/// @param newAmountToPay the new amount to pay for a subscription in wei.
38+
event AmountToPayUpdated(uint256 indexed newAmountToPay);
39+
40+
error InvalidDepositAmount(uint256 amountReceived, uint256 amountRequired);
3441

3542
/**
3643
* @notice Disables initializers for the implementation contract.
@@ -49,6 +56,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
4956
_transferOwnership(_owner);
5057

5158
paymentExpirationTimeSeconds = PAYMENT_VALID_UNTIL_SECONDS;
59+
amountToPayInWei = 1000000000000000000; // 1 ETH
5260
}
5361

5462
/**
@@ -71,15 +79,24 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
7179
emit PaymentExpirationTimeUpdated(newExpirationTimeInSeconds);
7280
}
7381

82+
/**
83+
* @notice Ensures only the owner can authorize upgrades.
84+
* @param newAmountToPay The new amount to pay for subscription in wei.
85+
*/
86+
function setAmountToPay(uint256 newAmountToPay) public onlyOwner() {
87+
amountToPayInWei = newAmountToPay;
88+
89+
emit AmountToPayUpdated(newAmountToPay);
90+
}
91+
7492
/**
7593
* @notice Accepts payments and validates they meet the minimum requirement.
7694
*/
7795
receive() external payable {
7896
uint256 amount = msg.value;
7997

80-
// 1 eth
81-
if (amount < 1000000000000000000) {
82-
revert InvalidDepositAmount(amount);
98+
if (amount < amountToPayInWei) {
99+
revert InvalidDepositAmount(amount, amountToPayInWei);
83100
}
84101

85102
emit UserPayment(msg.sender, amount, block.timestamp, block.timestamp + paymentExpirationTimeSeconds);

0 commit comments

Comments
 (0)