-
-
Notifications
You must be signed in to change notification settings - Fork 2k
[Delegation] Docs for v0.13 release #2294
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 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f2f951d
Add delegation scopes guide
AyushBherwani1998 3da6baa
Merge branch 'main' into feat/v0.13-dev
e897d01
Update dtk tutorial for v0.13
AyushBherwani1998 d0e365d
Update creating delegation references for v0.13
AyushBherwani1998 069914a
Update caveats to use new declarative format
AyushBherwani1998 b9dbe97
Adds guide: Check the delegation state
AyushBherwani1998 8641879
Adds guide: Constrain a scope
AyushBherwani1998 c635c75
Update reference section
AyushBherwani1998 694fe60
Update docs to use signer
AyushBherwani1998 1d16cff
Add DTK tutorial for creating an invite link (#2289)
alexandratran 78efdd9
resolve conflicts
fb509e6
revert the ew changes
f6cb791
revert ew change
58c3c37
v0.13 changes
AyushBherwani1998 6c23022
resolve conflicts
4d85ee9
minor edits
e74350b
remove todo
a4e8f2b
Merge branch 'main' into feat/v0.13-dev
AyushBherwani1998 f3d022b
use disallows instead of disables
faceed1
remove 7715 card from intro page
alexandratran 65b6b57
improve delegation scope ref description
820c550
add getMultiTokenPeriodEnforcerAvailableAmount action
db45a0d
Merge branch 'main' into feat/v0.13-dev
AyushBherwani1998 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
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
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
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
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
104 changes: 104 additions & 0 deletions
104
delegation-toolkit/guides/delegation/check-delegation-state.md
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,104 @@ | ||
| --- | ||
| description: Learn how to check the delegation state. | ||
| sidebar_label: Check the delegation state | ||
| toc_max_heading_level: 3 | ||
| --- | ||
|
|
||
| import Tabs from "@theme/Tabs"; | ||
| import TabItem from "@theme/TabItem"; | ||
|
|
||
| # Check the delegation state | ||
|
|
||
| When using [spending limit delegation scopes](use-delegation-scopes/spending-limit.md) or relevant [caveat enforcers](../../reference/delegation/caveats.md), | ||
| you might need to check the remaining transferrable amount in a delegation. | ||
| For example, if a delegation allows a user to spend 10 USDC per week and they have already spent 10 - n USDC in the current period, | ||
| you can determine how much of the allowance is still available for transfer. | ||
|
|
||
| Use the `CaveatEnforcerClient` to check the available balances for specific scopes or caveats. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - [Install and set up the Delegation Toolkit.](../../get-started/install.md) | ||
| - [Create a delegator account.](execute-on-smart-accounts-behalf.md#3-create-a-delegator-account) | ||
| - [Create a delegate account.](execute-on-smart-accounts-behalf.md#4-create-a-delegate-account) | ||
| - [Create a delegation with an ERC-20 periodic scope.](use-delegation-scopes/spending-limit.md#erc-20-periodic-scope) | ||
|
|
||
| ## Create a `CaveatEnforcerClient` | ||
|
|
||
| To check the delegation state, create a [`CaveatEnforcerClient`](../../reference/delegation/caveat-enforcer-client.md). | ||
| This client allows you to interact with the caveat enforcers of the delegation, and read the required state. | ||
|
|
||
| <Tabs> | ||
| <TabItem value="example.ts"> | ||
|
|
||
| ```typescript | ||
| import { environment, publicClient as client } from './config.ts' | ||
| import { createCaveatEnforcerClient } from '@metamask/delegation-toolkit' | ||
|
|
||
| const caveatEnforcerClient = createCaveatEnforcerClient({ | ||
| environment, | ||
| client, | ||
| }) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="config.ts"> | ||
|
|
||
| ```typescript | ||
| import { sepolia as chain } from 'viem/chains' | ||
| import { createPublicClient, http } from 'viem' | ||
| import { getDeleGatorEnvironment } from '@metamask/delegation-toolkit' | ||
|
|
||
| export const environment = getDeleGatorEnvironment(chain.id) | ||
|
|
||
| export const publicClient = createPublicClient({ | ||
| chain, | ||
| transport: http(), | ||
| }) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## Read the caveat enforcer state | ||
|
|
||
| This example uses the [`getErc20PeriodTransferEnforcerAvailableAmount`](../../reference/delegation/caveat-enforcer-client.md#geterc20periodtransferenforceravailableamount) method to read the state and retrieve the remaining amount for the current transfer period. | ||
|
|
||
| <Tabs> | ||
| <TabItem value="example.ts"> | ||
|
|
||
| ```typescript | ||
| import { delegation } './config.ts' | ||
|
|
||
| // Returns the available amount for current period. | ||
| const { availableAmount } = await caveatEnforcerClient.getErc20PeriodTransferEnforcerAvailableAmount({ | ||
| delegation, | ||
| }) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| <TabItem value="config.ts"> | ||
|
|
||
| ```typescript | ||
| import { createDelegation } from '@metamask/delegation-toolkit' | ||
|
|
||
| export const delegation = createDelegation({ | ||
| scope: { | ||
| type: 'erc20PeriodTransfer', | ||
| tokenAddress: '0xb4aE654Aca577781Ca1c5DE8FbE60c2F423f37da', | ||
| periodAmount: 1000000000000000000n, | ||
| periodDuration: 86400, | ||
| startDate: 1743763600, | ||
| }, | ||
| to: delegateAccount, | ||
| from: delegatorAccount, | ||
| environment: delegatorAccount.environment, | ||
| }) | ||
| ``` | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ## Next steps | ||
|
|
||
| See the [Caveat Enforcer Client reference](../../reference/delegation/caveat-enforcer-client.md) for the full list of available methods. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.