Skip to content

Commit 8f6c794

Browse files
add support for CaveatType enum
* add caveattype enum docs * resolve review comments * fix anchor link
1 parent 9e4bcc8 commit 8f6c794

8 files changed

Lines changed: 150 additions & 44 deletions

File tree

smart-accounts-kit/concepts/delegation/caveat-enforcers.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,16 @@ The `CaveatBuilder` provides a developer-friendly TypeScript API that:
128128
- Handles the creation of the `caveats` array needed when creating a delegation.
129129

130130
Each [caveat type](../../reference/delegation/caveats.md) in the `CaveatBuilder`
131-
corresponds to a specific caveat enforcer contract. For example, when you use:
131+
corresponds to a specific caveat enforcer contract. The following example uses an [`AllowedTargets`](../../reference/delegation/caveats.md#allowedtargets) caveat.
132132

133133
```typescript
134-
caveatBuilder.addCaveat("allowedTargets", ["0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92"]);
134+
const caveats = [{
135+
type: CaveatType.AllowedTargets,
136+
targets: [
137+
"0xc11F3a8E5C7D16b75c9E2F60d26f5321C6Af5E92",
138+
"0xB2880E3862f1024cAC05E66095148C0a9251718b",
139+
]
140+
}];
135141
```
136142

137143
The builder is creating a caveat that references the

smart-accounts-kit/guides/advanced-permissions/create-redelegation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ This example uses the [`limitedCalls`](../../reference/delegation/caveats.md#lim
190190
```ts
191191
// Use the config from previous step.
192192
import { sessionAccount, agentSmartAccount, tokenAddress } from './config.ts';
193+
import { CaveatType } from '@metamask/smart-accounts-kit'
193194
import { createCaveatBuilder, hashDelegation } from '@metamask/smart-accounts-kit/utils'
194195

195196
const caveatBuilder = createCaveatBuilder(sessionAccount.environment)
196197

197-
const caveats = caveatBuilder.addCaveat('limitedCalls', { limit: 1 })
198+
const caveats = caveatBuilder.addCaveat(CaveatType.LimitedCalls, { limit: 1 })
198199

199200
const redelegation: Delegation = {
200201
delegate: sessionAccount.address,

smart-accounts-kit/guides/delegation/create-redelegation.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ This example uses the [`limitedCalls`](../../reference/delegation/caveats.md#lim
154154
```ts
155155
// Use the config from previous step.
156156
import { bobSmartAccount, carolSmartAccount } from "./config.ts"
157+
import { CaveatType } from '@metamask/smart-accounts-kit'
157158
import { createCaveatBuilder, hashDelegation } from '@metamask/smart-accounts-kit/utils'
158159

159160
const caveatBuilder = createCaveatBuilder(bobSmartAccount.environment)
160161

161-
const caveats = caveatBuilder.addCaveat('limitedCalls', { limit: 1 })
162+
const caveats = caveatBuilder.addCaveat(CaveatType.LimitedCalls, { limit: 1 })
162163

163164
const redelegation: Delegation = {
164165
delegate: bobSmartAccount.address,

smart-accounts-kit/guides/delegation/use-delegation-scopes/constrain-scope.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ she can apply the [`timestamp`](../../../reference/delegation/caveats.md#timesta
2626
The following example creates a delegation using [`createDelegation`](../../../reference/delegation/index.md#createdelegation), applies the ERC-20 transfer scope with a spending limit of 10 USDC, and applies the `timestamp` caveat enforcer to restrict the delegation's validity to a seven-day period:
2727

2828
```typescript
29-
import { createDelegation, ScopeType } from "@metamask/smart-accounts-kit";
29+
import { createDelegation, ScopeType, CaveatType } from "@metamask/smart-accounts-kit";
3030

3131
// Convert milliseconds to seconds.
3232
const currentTime = Math.floor(Date.now() / 1000);
@@ -35,7 +35,7 @@ const currentTime = Math.floor(Date.now() / 1000);
3535
const beforeThreshold = currentTime + 604800;
3636

3737
const caveats = [{
38-
type: "timestamp",
38+
type: CaveatType.Timestamp,
3939
afterThreshold: currentTime,
4040
beforeThreshold,
4141
}];

smart-accounts-kit/reference/delegation/caveat-enforcer-client.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ const { availableAmount } = await caveatEnforcerClient.getMultiTokenPeriodEnforc
311311
<TabItem value="config.ts">
312312
313313
```typescript
314-
import { createDelegation, getSmartAccountsEnvironment, ROOT_AUTHORITY } from '@metamask/smart-accounts-kit'
314+
import { createDelegation, getSmartAccountsEnvironment, ROOT_AUTHORITY, CaveatType } from '@metamask/smart-accounts-kit'
315315
import { createCaveatBuilder } from '@metamask/smart-accounts-kit/utils'
316316
import { sepolia as chain } from 'viem/chains'
317317
import { parseUnits, parseEther } from 'viem'
@@ -343,10 +343,7 @@ const tokenConfigs = [
343343
}
344344
]
345345

346-
const caveats = caveatBuilder.addCaveat({
347-
'multiTokenPeriod',
348-
tokenConfigs
349-
})
346+
const caveats = caveatBuilder.addCaveat(CaveatType.MultiTokenPeriod, tokenConfigs)
350347

351348
export const delegation: Delegation = {
352349
delegate: 'DELEGATE_ADDRESS',

0 commit comments

Comments
 (0)