Skip to content

fix(account-sdk): return a status for spend permissions outside their window - #429

Open
erkancamli wants to merge 1 commit into
base:masterfrom
erkancamli:fix/permission-status-outside-window
Open

erkancamli wants to merge 1 commit into
base:masterfrom
erkancamli:fix/permission-status-outside-window

Conversation

@erkancamli

Copy link
Copy Markdown

Summary

Fixes #422.

SpendPermissionManager.getCurrentPeriod reverts with BeforeSpendPermissionStart before start and AfterSpendPermissionEnd once block.timestamp >= end. getPermissionStatus read it in a strict multicall, so for any permission outside [start, end) it threw Multicall execution failed: Failed to fetch current period and isExpired: true was never returned. Through it:

  • getSubscriptionStatus threw for an expired subscription instead of returning isSubscribed: false.
  • getSubscriptionStatus never reached its own "Subscription has not started yet" error for a future subscription.

Changes in getPermissionStatus.ts:

  • The multicall now uses allowPartialFailure: true.
  • When getCurrentPeriod fails and the permission is outside its window, the period comes from the existing calculateCurrentPeriod helper and remainingSpend is 0. Inside the window a getCurrentPeriod failure still throws, as before.
  • isExpired is now now >= end, matching the contract, instead of now > end.

How did you test your changes?

  • Two new unit tests: one where getCurrentPeriod reverts at end, one where it reverts before start. Both fail on master and pass with this change. The existing getCurrentPeriod failure test now pins the clock inside the window, so it still checks that the error surfaces there.
  • An offline repro with a real viem client, whose transport answers multicall3 aggregate3 the way the deployed contract does. Before the change, three cases threw: expired permission, expired subscription and not-started subscription. After it:
    • the expired permission gives isExpired: true, isActive: false, remainingSpend: 0;
    • the expired subscription gives isSubscribed: false;
    • the not-started subscription throws "Subscription has not started yet".
  • yarn vitest --run in packages/account-sdk: 76 files, 1050 tests pass. yarn typecheck passes. biome lint and the repo's format:check settings are clean on the changed files.

… window

SpendPermissionManager.getCurrentPeriod reverts with
BeforeSpendPermissionStart before start and AfterSpendPermissionEnd once
block.timestamp >= end. getPermissionStatus read it in a strict
multicall, so for any permission outside [start, end) it threw
"Multicall execution failed: Failed to fetch current period" and never
returned isExpired: true. getSubscriptionStatus inherited the error, so
an expired subscription threw instead of returning isSubscribed: false,
and a subscription that has not started never reached its own
"Subscription has not started yet" error.

Read the three values with allowPartialFailure. When getCurrentPeriod
fails outside the window, compute the period with calculateCurrentPeriod
and report remainingSpend 0. Inside the window a failure still throws.
isExpired now uses now >= end, as the contract does.

Fixes base#422
@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
1 if authored by an app that is not allowlisted and lacks verified human attribution 0
Sum 1

This branch has not been deployed

No deployments
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.

Bug: getPermissionStatus throws for a spend permission that has expired or not started, so isExpired is never true

2 participants