Skip to content

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

Merged

Conversation

devin-ai-integration[bot]
Copy link
Contributor

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

  • Fixed a bug in Scheduler.sol where it was checking status.isActive instead of params.isActive
  • Added a check in addFunds to ensure that active subscriptions maintain minimum balance after funds are added
  • Added tests in PulseScheduler.t.sol to verify this behavior for both regular and permanent subscriptions

Testing

  • Added test testAddFundsEnforcesMinimumBalance to verify minimum balance check for regular subscriptions
  • Added test testAddFundsEnforcesMinimumBalanceForPermanentSubscription to verify minimum balance check for permanent subscriptions
  • All tests pass successfully

Link to Devin run: https://app.devin.ai/sessions/6a8af4d12771419d86aff4d8c2663944
Requested by: Tejas Badadare (tejas@dourolabs.xyz)

devin-ai-integration bot and others added 6 commits May 12, 2025 17:55
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>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link

vercel bot commented May 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 9:48pm
component-library ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 9:48pm
developer-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 9:48pm
entropy-debugger ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 9:48pm
entropy-explorer ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 9:48pm
insights ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 9:48pm
proposals ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 9:48pm
staking ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 9:48pm

@tejasbadadare tejasbadadare changed the title fix: ensure subscription balance is greater than minimum balance after adding funds fix(pulse): ensure subscription balance is greater than minimum balance after adding funds May 12, 2025
@tejasbadadare tejasbadadare changed the base branch from main to devin/1747072255-add-max-deposit-limit-for-permanent-subscriptions May 12, 2025 19:10
@tejasbadadare tejasbadadare self-assigned this May 16, 2025
Copy link
Contributor Author

Closing due to inactivity for more than 7 days.

Comment on lines 583 to 612
// 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"
);
Copy link
Collaborator

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()
Copy link
Collaborator

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.

Copy link
Collaborator

@ali-behjati ali-behjati left a 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>
@vercel vercel bot temporarily deployed to Preview – staking May 27, 2025 13:05 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer May 27, 2025 13:05 Inactive
@vercel vercel bot temporarily deployed to Preview – insights May 27, 2025 13:05 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library May 27, 2025 13:05 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals May 27, 2025 13:05 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library May 27, 2025 13:27 Inactive
@vercel vercel bot temporarily deployed to Preview – staking May 27, 2025 13:27 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference May 27, 2025 13:27 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals May 27, 2025 13:27 Inactive
@vercel vercel bot temporarily deployed to Preview – insights May 27, 2025 13:27 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer May 27, 2025 13:27 Inactive
Co-Authored-By: Tejas Badadare <tejas@dourolabs.xyz>
@vercel vercel bot temporarily deployed to Preview – component-library May 27, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-debugger May 27, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals May 27, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – insights May 27, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference May 27, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – staking May 27, 2025 13:40 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer May 27, 2025 13:40 Inactive
Base automatically changed from devin/1747072255-add-max-deposit-limit-for-permanent-subscriptions to main May 27, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants