Repository navigation
fix(account-sdk): return a status for spend permissions outside their window - #429
Open
erkancamli wants to merge 1 commit into
Open
erkancamli wants to merge 1 commit into
erkancamli wants to merge 1 commit into
Conversation
… 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
Collaborator
🟡 Heimdall Review Status
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #422.
SpendPermissionManager.getCurrentPeriodreverts withBeforeSpendPermissionStartbeforestartandAfterSpendPermissionEndonceblock.timestamp >= end.getPermissionStatusread it in a strict multicall, so for any permission outside[start, end)it threwMulticall execution failed: Failed to fetch current periodandisExpired: truewas never returned. Through it:getSubscriptionStatusthrew for an expired subscription instead of returningisSubscribed: false.getSubscriptionStatusnever reached its own "Subscription has not started yet" error for a future subscription.Changes in
getPermissionStatus.ts:allowPartialFailure: true.getCurrentPeriodfails and the permission is outside its window, the period comes from the existingcalculateCurrentPeriodhelper andremainingSpendis 0. Inside the window agetCurrentPeriodfailure still throws, as before.isExpiredis nownow >= end, matching the contract, instead ofnow > end.How did you test your changes?
getCurrentPeriodreverts atend, one where it reverts beforestart. Both fail on master and pass with this change. The existinggetCurrentPeriodfailure test now pins the clock inside the window, so it still checks that the error surfaces there.aggregate3the way the deployed contract does. Before the change, three cases threw: expired permission, expired subscription and not-started subscription. After it:isExpired: true, isActive: false, remainingSpend: 0;isSubscribed: false;yarn vitest --runinpackages/account-sdk: 76 files, 1050 tests pass.yarn typecheckpasses.biome lintand the repo'sformat:checksettings are clean on the changed files.