Skip to content

Commit 05dd72b

Browse files
Add a withdrawal method to send the funds to a recipient
1 parent 42a7330 commit 05dd72b

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

contracts/script/deploy/AggregationModePaymentServiceDeployer.s.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ 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");
1415

1516
vm.startBroadcast();
1617

1718
AggregationModePaymentService implementation = new AggregationModePaymentService();
1819
ERC1967Proxy proxy =
19-
new ERC1967Proxy(address(implementation), abi.encodeWithSignature("initialize(address)", owner));
20+
new ERC1967Proxy(address(implementation), abi.encodeWithSignature("initialize(address,address)", owner, recipient));
2021

2122
vm.stopBroadcast();
2223

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"permissions": {
1313
"owner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
14-
"paymentServiceOwner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955"
14+
"paymentServiceOwner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955",
15+
"recipient": "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f"
1516
}
1617
}

contracts/src/core/AggregationModePaymentService.sol

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
2020
/// @notice The amount to pay for a subscription in wei.
2121
uint256 public amountToPayInWei;
2222

23+
/// @notice The address where the payment funds will be sent.
24+
address public paymentFundsRecipient;
25+
2326
/**
2427
* @notice Emitted when a user deposits funds to purchase service time.
2528
* @param user Address that sent the payment.
@@ -33,10 +36,19 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
3336
/// @param newExpirationTime the new expiration time in seconds
3437
event PaymentExpirationTimeUpdated(uint256 indexed newExpirationTime);
3538

36-
/// @notice Event emitted when the payment expiration time is updated
39+
/// @notice Event emitted when the amount to pay for subscription is updated
3740
/// @param newAmountToPay the new amount to pay for a subscription in wei.
3841
event AmountToPayUpdated(uint256 indexed newAmountToPay);
3942

43+
/// @notice Event emitted when the funds recipient is updated
44+
/// @param newFundsRecipient the new address for receiving the funds on withdrawal.
45+
event FundsRecipientUpdated(address indexed newFundsRecipient);
46+
47+
/// @notice Event emitted when the balance is withdrawn to the recipient address
48+
/// @param recipient the address where the funds will be sent
49+
/// @param amount the amont send to the recipient address
50+
event FundsWithdrawn(address indexed recipient, uint256 amount);
51+
4052
error InvalidDepositAmount(uint256 amountReceived, uint256 amountRequired);
4153

4254
/**
@@ -50,13 +62,14 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
5062
* @notice Initializes the contract and transfers ownership to the provided address.
5163
* @param _owner Address that becomes the contract owner.
5264
*/
53-
function initialize(address _owner) public initializer {
65+
function initialize(address _owner, address _paymentFundsRecipient) public initializer {
5466
__Ownable_init();
5567
__UUPSUpgradeable_init();
5668
_transferOwnership(_owner);
5769

5870
paymentExpirationTimeSeconds = PAYMENT_VALID_UNTIL_SECONDS;
5971
amountToPayInWei = 1000000000000000000; // 1 ETH
72+
paymentFundsRecipient = _paymentFundsRecipient;
6073
}
6174

6275
/**
@@ -70,7 +83,7 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
7083
{}
7184

7285
/**
73-
* @notice Ensures only the owner can authorize upgrades.
86+
* @notice Sets the new expiration time. Only callable by the owner
7487
* @param newExpirationTimeInSeconds The new expiration time for the users payments in seconds.
7588
*/
7689
function setPaymentExpirationTimeSeconds(uint256 newExpirationTimeInSeconds) public onlyOwner() {
@@ -80,7 +93,17 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
8093
}
8194

8295
/**
83-
* @notice Ensures only the owner can authorize upgrades.
96+
* @notice Sets the new amount to pay. Only callable by the owner
97+
* @param newRecipient The new address for receiving the funds on withdrawal.
98+
*/
99+
function setFundsRecipientAddress(address newRecipient) public onlyOwner() {
100+
paymentFundsRecipient = newRecipient;
101+
102+
emit FundsRecipientUpdated(newRecipient);
103+
}
104+
105+
/**
106+
* @notice Sets the new amount to pay. Only callable by the owner
84107
* @param newAmountToPay The new amount to pay for subscription in wei.
85108
*/
86109
function setAmountToPay(uint256 newAmountToPay) public onlyOwner() {
@@ -101,4 +124,13 @@ contract AggregationModePaymentService is Initializable, OwnableUpgradeable, UUP
101124

102125
emit UserPayment(msg.sender, amount, block.timestamp, block.timestamp + paymentExpirationTimeSeconds);
103126
}
127+
128+
/**
129+
* @notice Withdraws the contract balance to the recipient address.
130+
*/
131+
function withdraw() external onlyOwner {
132+
uint256 balance = address(this).balance;
133+
payable(paymentFundsRecipient).transfer(balance);
134+
emit FundsWithdrawn(paymentFundsRecipient, balance);
135+
}
104136
}

0 commit comments

Comments
 (0)