Skip to content

Commit 3ef5e7f

Browse files
committed
feat: add permanent subscriptions, clean up tests
1 parent 104df2e commit 3ef5e7f

File tree

4 files changed

+257
-236
lines changed

4 files changed

+257
-236
lines changed

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

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,33 @@ abstract contract Scheduler is IScheduler, SchedulerState {
9898
bool wasActive = currentParams.isActive;
9999
bool willBeActive = newParams.isActive;
100100

101+
// Check for permanent subscription restrictions
102+
if (currentParams.isPermanent) {
103+
// Cannot disable isPermanent flag once set
104+
if (!newParams.isPermanent) {
105+
revert IllegalPermanentSubscriptionModification();
106+
}
107+
108+
// Cannot remove price feeds from a permanent subscription
109+
if (newParams.priceIds.length < currentParams.priceIds.length) {
110+
revert IllegalPermanentSubscriptionModification();
111+
}
112+
113+
// Check that all existing price IDs are preserved
114+
for (uint i = 0; i < currentParams.priceIds.length; i++) {
115+
bool found = false;
116+
for (uint j = 0; j < newParams.priceIds.length; j++) {
117+
if (currentParams.priceIds[i] == newParams.priceIds[j]) {
118+
found = true;
119+
break;
120+
}
121+
}
122+
if (!found) {
123+
revert IllegalPermanentSubscriptionModification();
124+
}
125+
}
126+
}
127+
101128
// If subscription is inactive and will remain inactive, no need to validate parameters
102129
if (!wasActive && !willBeActive) {
103130
// Update subscription parameters
@@ -487,9 +514,7 @@ abstract contract Scheduler is IScheduler, SchedulerState {
487514

488515
/// BALANCE MANAGEMENT
489516

490-
function addFunds(
491-
uint256 subscriptionId
492-
) external payable override onlyManager(subscriptionId) {
517+
function addFunds(uint256 subscriptionId) external payable override {
493518
if (!_state.subscriptionParams[subscriptionId].isActive) {
494519
revert InactiveSubscription();
495520
}
@@ -508,6 +533,11 @@ abstract contract Scheduler is IScheduler, SchedulerState {
508533
subscriptionId
509534
];
510535

536+
// Prevent withdrawals from permanent subscriptions
537+
if (params.isPermanent) {
538+
revert IllegalPermanentSubscriptionModification();
539+
}
540+
511541
if (status.balanceInWei < amount) {
512542
revert InsufficientBalance();
513543
}

target_chains/ethereum/contracts/contracts/pulse/scheduler/SchedulerErrors.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ error InvalidGasConfig();
1212
error PriceSlotMismatch();
1313
error TooManyPriceIds(uint256 provided, uint256 maximum);
1414
error UpdateConditionsNotMet();
15+
error IllegalPermanentSubscriptionModification();
1516
error TimestampOlderThanLastUpdate(
1617
uint256 providedUpdateTimestamp,
1718
uint256 lastUpdatedAt

target_chains/ethereum/contracts/contracts/pulse/scheduler/SchedulerState.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ contract SchedulerState {
4141
address[] readerWhitelist;
4242
bool whitelistEnabled;
4343
bool isActive;
44+
bool isPermanent;
4445
UpdateCriteria updateCriteria;
4546
GasConfig gasConfig;
4647
}

0 commit comments

Comments
 (0)