-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[Smart Accounts Kit][Troubleshoot] Allowance exceeded troubleshoot page #2774
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
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- | ||
| description: How to resolve allowance exceeded errors when redeeming delegations. | ||
| sidebar_label: Allowance exceeded | ||
| keywords: [allowance, allowance exceeded, erc20 transfer amount exceeded, spending limit, troubleshooting] | ||
| --- | ||
|
|
||
| # Allowance exceeded | ||
|
|
||
| Spending limit [caveat enforcers](../concepts/delegation/caveat-enforcers.md) revert with an | ||
| `allowance-exceeded` error in the following cases. | ||
|
|
||
| ## Spending limit exceeded | ||
|
|
||
| The delegation's spending limit has been fully or partially used up by previous redemptions. | ||
| Enforcers track cumulative spending on-chain using the delegation hash as a key, and revert when | ||
| the next transfer exceeds the allowed limit. | ||
|
|
||
| ### Solution | ||
|
|
||
| Use the [`CaveatEnforcerClient`](../reference/delegation/caveat-enforcer-client.md) to check the | ||
| available amount before redeeming the delegation. | ||
|
|
||
| If the available amount is insufficient, you must wait for the next period (for periodic | ||
| enforcers) or for more tokens to accrue (for streaming enforcers). For fixed-limit enforcers, | ||
| create a new delegation with a higher limit. | ||
|
|
||
| ## Delegation hash collision | ||
|
|
||
| If you create a new delegation with the same parameters as a previous delegation, both produce | ||
| the same delegation hash. | ||
|
|
||
| Enforcers track spent amounts using the delegation hash as a key. When two delegations share the | ||
| same hash, they also share the same spent balance. This means the new delegation can immediately | ||
| revert with `allowance-exceeded`, even if you haven't redeemed it before. | ||
|
|
||
| ### Solution | ||
|
|
||
| Use a unique `salt` when creating the delegation. This produces a different delegation hash, | ||
| giving the new delegation a fresh spending allowance. | ||
|
|
||
| ```typescript | ||
| import { createDelegation, ScopeType } from "@metamask/smart-accounts-kit"; | ||
| import { parseUnits } from "viem"; | ||
|
|
||
| const delegation = createDelegation({ | ||
| scope: { | ||
| type: ScopeType.Erc20TransferAmount, | ||
| tokenAddress: "0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92", | ||
| // USDC has 6 decimal places. | ||
| maxAmount: parseUnits("10", 6), | ||
| }, | ||
| salt: "0x00131412", | ||
| to: delegateAccount, | ||
| from: delegatorAccount, | ||
| environment: delegatorAccount.environment, | ||
| }); | ||
| ``` | ||
Oops, something went wrong.
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.
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.