-
Notifications
You must be signed in to change notification settings - Fork 256
fix(pulse): ensure subscription balance is greater than minimum balance after adding funds #2680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pulse): ensure subscription balance is greater than minimum balance after adding funds #2680
Conversation
Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
…r adding funds Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Closing due to inactivity for more than 7 days. |
// Now create a new subscription but don't fund it fully | ||
SchedulerState.SubscriptionParams | ||
memory newParams = createDefaultSubscriptionParams( | ||
2, | ||
address(reader) | ||
); | ||
|
||
// Calculate minimum balance for this new subscription | ||
uint256 newMinimumBalance = scheduler.getMinimumBalance( | ||
uint8(newParams.priceIds.length) | ||
); | ||
|
||
// Try to create with insufficient funds | ||
uint256 insufficientFunds = newMinimumBalance - 1 wei; | ||
vm.expectRevert(abi.encodeWithSelector(InsufficientBalance.selector)); | ||
scheduler.createSubscription{value: insufficientFunds}(newParams); | ||
|
||
// Create with sufficient funds | ||
uint256 newSubscriptionId = scheduler.createSubscription{ | ||
value: newMinimumBalance | ||
}(newParams); | ||
|
||
// Verify subscription was created with minimum balance | ||
(, SchedulerState.SubscriptionStatus memory newStatus) = scheduler | ||
.getSubscription(newSubscriptionId); | ||
assertEq( | ||
newStatus.balanceInWei, | ||
newMinimumBalance, | ||
"New subscription balance should equal minimum balance" | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not testing balance check in addFunds
. here you need to send some updates to drain the balance and then try to add funds
); | ||
} | ||
|
||
function testAddFundsEnforcesMinimumBalanceForPermanentSubscription() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think that this is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve it but let's make sure tests get fixed.
Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
…evin/1747076033-ensure-minimum-balance-after-adding-funds
Ensure Subscription Balance > Minimum Balance After Adding Funds
This PR adds a check in the
addFunds
function to ensure that the subscription balance is greater than the minimum balance after funds are added. This ensures that active subscriptions always maintain the required minimum balance.Changes
Scheduler.sol
where it was checkingstatus.isActive
instead ofparams.isActive
addFunds
to ensure that active subscriptions maintain minimum balance after funds are addedPulseScheduler.t.sol
to verify this behavior for both regular and permanent subscriptionsTesting
testAddFundsEnforcesMinimumBalance
to verify minimum balance check for regular subscriptionstestAddFundsEnforcesMinimumBalanceForPermanentSubscription
to verify minimum balance check for permanent subscriptionsLink to Devin run: https://app.devin.ai/sessions/6a8af4d12771419d86aff4d8c2663944
Requested by: Tejas Badadare (tejas@dourolabs.xyz)