Skip to content

Commit 584a098

Browse files
feat(aggregation-mode): add setters and subscriptions to agg mode Payment Service (#2200)
1 parent 585fad0 commit 584a098

File tree

6 files changed

+102
-18
lines changed

6 files changed

+102
-18
lines changed

aggregation_mode/batcher/abi/AggregationModePaymentService.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

contracts/script/deploy/AggregationModePaymentServiceDeployer.s.sol

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ contract AggregationModePaymentServiceDeployer is Script {
1111
string memory configData = vm.readFile(configPath);
1212

1313
address owner = stdJson.readAddress(configData, ".permissions.paymentServiceOwner");
14+
address recipient = stdJson.readAddress(configData, ".permissions.recipient");
15+
uint256 amountToPay = stdJson.readUint(configData, ".amounts.amountToPayInWei");
16+
uint256 paymentExpirationTimeSeconds = stdJson.readUint(configData, ".amounts.paymentExpirationTimeSeconds");
1417

1518
vm.startBroadcast();
1619

1720
AggregationModePaymentService implementation = new AggregationModePaymentService();
18-
ERC1967Proxy proxy =
19-
new ERC1967Proxy(address(implementation), abi.encodeWithSignature("initialize(address)", owner));
21+
ERC1967Proxy proxy = new ERC1967Proxy(
22+
address(implementation),
23+
abi.encodeWithSignature(
24+
"initialize(address,address,uint256,uint256)",
25+
owner,
26+
recipient,
27+
amountToPay,
28+
paymentExpirationTimeSeconds
29+
)
30+
);
2031

2132
vm.stopBroadcast();
2233

contracts/script/deploy/config/devnet/proof-aggregator-service.devnet.config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
"sp1AggregationProgramVKHash": "0x00d6e32a34f68ea643362b96615591c94ee0bf99ee871740ab2337966a4f77af",
1010
"risc0AggregationProgramImageId": "0x8908f01022827e80a5de71908c16ee44f4a467236df20f62e7c994491629d74c"
1111
},
12+
"amounts": {
13+
"amountToPayInWei": 1000000000000000000,
14+
"paymentExpirationTimeSeconds": 86400
15+
},
1216
"permissions": {
1317
"owner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
14-
"paymentServiceOwner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955"
18+
"paymentServiceOwner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
19+
"recipient": "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f"
1520
}
1621
}

contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

contracts/src/core/AggregationModePaymentService.sol

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
1313
contract 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

Comments
 (0)