Skip to content

Commit 4dfaeed

Browse files
committed
feat: make updateSubscription payable
1 parent 59516b6 commit 4dfaeed

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

target_chains/ethereum/contracts/contracts/pulse/IScheduler.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ interface IScheduler is SchedulerEvents {
3636

3737
/**
3838
* @notice Updates an existing subscription
39-
* @dev You can activate or deactivate a subscription by setting isActive to true or false.
40-
* @dev Reactivating a subscription requires the subscription to hold at least the minimum balance (calculated by getMinimumBalance()).
39+
* @dev You can activate or deactivate a subscription by setting isActive to true or false. Reactivating a subscription
40+
* requires the subscription to hold at least the minimum balance (calculated by getMinimumBalance()).
41+
* @dev Any Ether sent with this call (`msg.value`) will be added to the subscription's balance before processing the update.
4142
* @param subscriptionId The ID of the subscription to update
4243
* @param newSubscriptionParams The new parameters for the subscription
4344
*/
4445
function updateSubscription(
4546
uint256 subscriptionId,
4647
SchedulerState.SubscriptionParams calldata newSubscriptionParams
47-
) external;
48+
) external payable;
4849

4950
/**
5051
* @notice Updates price feeds for a subscription.

target_chains/ethereum/contracts/contracts/pulse/Scheduler.sol

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ abstract contract Scheduler is IScheduler, SchedulerState {
7373
function updateSubscription(
7474
uint256 subscriptionId,
7575
SubscriptionParams memory newParams
76-
) external override onlyManager(subscriptionId) {
76+
) external payable override onlyManager(subscriptionId) {
7777
SubscriptionStatus storage currentStatus = _state.subscriptionStatuses[
7878
subscriptionId
7979
];
8080
SubscriptionParams storage currentParams = _state.subscriptionParams[
8181
subscriptionId
8282
];
8383

84+
// Add incoming funds to balance
85+
currentStatus.balanceInWei += msg.value;
86+
8487
// Updates to permanent subscriptions are not allowed
8588
if (currentParams.isPermanent) {
8689
revert CannotUpdatePermanentSubscription();

target_chains/ethereum/contracts/forge-test/PulseScheduler.t.sol

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,17 +1133,16 @@ contract SchedulerTest is Test, SchedulerEvents, PulseSchedulerTestUtils {
11331133
vm.expectRevert(abi.encodeWithSelector(InsufficientBalance.selector));
11341134
scheduler.updateSubscription(subscriptionId, newParams);
11351135

1136-
// Action 2: Add enough funds to meet the new minimum balance
1136+
// Action 2: Supply enough funds to the updateSubscription call to meet the new minimum balance
11371137
uint256 newMinimumBalance = scheduler.getMinimumBalance(newNumFeeds);
11381138
uint256 requiredFunds = newMinimumBalance - initialMinimumBalance;
1139-
scheduler.addFunds{value: requiredFunds}(subscriptionId);
11401139

1141-
// Verification 2: Update should now succeed
1142-
vm.expectEmit();
1143-
emit SubscriptionUpdated(subscriptionId);
1144-
scheduler.updateSubscription(subscriptionId, newParams);
1140+
scheduler.updateSubscription{value: requiredFunds}(
1141+
subscriptionId,
1142+
newParams
1143+
);
11451144

1146-
// Verify the number of price IDs was updated
1145+
// Verification 2: Update should now succeed
11471146
(SchedulerState.SubscriptionParams memory updatedParams, ) = scheduler
11481147
.getSubscription(subscriptionId);
11491148
assertEq(
@@ -1173,11 +1172,6 @@ contract SchedulerTest is Test, SchedulerEvents, PulseSchedulerTestUtils {
11731172
newParams_deact.isActive = false; // Deactivate
11741173

11751174
// Action 3: Update (should succeed even with insufficient funds for 4 feeds)
1176-
vm.expectEmit();
1177-
emit SubscriptionDeactivated(subId_deact);
1178-
vm.expectEmit();
1179-
emit SubscriptionUpdated(subId_deact);
1180-
// No revert expected here
11811175
scheduler.updateSubscription(subId_deact, newParams_deact);
11821176

11831177
// Verification 3: Subscription should be inactive and have 4 feeds

0 commit comments

Comments
 (0)