feat: add CaveatType enum and integrate into core caveat builder#179
feat: add CaveatType enum and integrate into core caveat builder#179
Conversation
packages/smart-accounts-kit/src/caveatBuilder/coreCaveatBuilder.ts
Outdated
Show resolved
Hide resolved
packages/smart-accounts-kit/src/caveatBuilder/coreCaveatBuilder.ts
Outdated
Show resolved
Hide resolved
packages/smart-accounts-kit/src/caveatBuilder/coreCaveatBuilder.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
packages/smart-accounts-kit/src/caveatBuilder/coreCaveatBuilder.ts
Outdated
Show resolved
Hide resolved
jeffsmale90
left a comment
There was a problem hiding this comment.
I checked this with the createDelegation interface and it all works really well! Such a nice simple solution.
I think some test coverage and this should be g2g.
| ownershipTransfer: typeof ownershipTransferBuilder; | ||
| }; | ||
|
|
||
| type CaveatMapLookup<Key extends keyof _CoreCaveatMap> = _CoreCaveatMap[Key]; |
There was a problem hiding this comment.
This looks so nice and simple! Do we need this intermediary CaveatMapLookup though?
I think we can just
type CoreCaveatMap = _CoreCaveatMap & {
[K in CaveatType as `${K}`]: _CoreCaveatMap[`${K}`];
};
I think we should rename _CoreCaveatMap to something more meaningful - maybe your CaveatMapLookup is a good name for it!
packages/smart-accounts-kit/src/caveatBuilder/coreCaveatBuilder.ts
Outdated
Show resolved
Hide resolved
jeffsmale90
left a comment
There was a problem hiding this comment.
Looking good! A possible type rename, but otherwise looks awesome.
…update CoreCaveatMap type definition
📝 Description
Added comprehensive
CaveatTypeenum to the Smart Accounts Kit and fully integrated it into the core caveat builder system. This provides developers with a type-safe, enum-based approach to specifying caveat types throughout the codebase, complementing the existing string literal support.🔄 What Changed?
Core Changes:
Created
CaveatTypeenum inconstants.tswith 32 caveat type members:Erc20TransferAmount,Erc20BalanceChange,NativeTokenTransferAmount,NativeBalanceChange, etc.Timestamp,BlockNumber,LimitedCallsAllowedMethods,AllowedTargets,AllowedCalldata,DeployedExactCalldata,ExactExecution,MultiTokenPeriod,OwnershipTransfer, and moreExported
CaveatTypefrom main package index (src/index.ts) for public API accessEnhanced type system in
coreCaveatBuilder.ts:CoreCaveatMapinto_CoreCaveatMap(base type) andCoreCaveatMap(extended type)CaveatTypeenum values to their corresponding builder functionsAdded comprehensive test coverage:
🚀 Why?
ScopeTypeandImplementationenums in the codebase🧪 How to Test?
npx vitest run test/caveatBuilder/createCaveatBuilder.test.tsCaveatType.AllowedMethodsand'allowedMethods'produce identical outputs📋 Checklist
CaveatTypeadded to index.ts)🔗 Related Issues
Related to PR #170 (String Literal Support for addCaveat)
📚 Additional Notes
The
CaveatTypeenum is now the recommended approach for specifying caveat types in production code. It provides the same functionality as string literals but with full type safety and IDE support. The implementation maintains backward compatibility with the string literal approach, allowing for gradual migration in existing codebases.Key enum members:
Erc20TransferAmount,NativeTokenTransferAmount,Erc20PeriodTransfer,NativeTokenPeriodTransferErc20BalanceChange,NativeBalanceChange,Erc721BalanceChange,Erc1155BalanceChangeTimestamp,BlockNumber,LimitedCallsAllowedMethods,AllowedTargets,AllowedCalldata,Deployed,RedeemerExactCalldata,ExactExecution,ExactCalldataBatch,ExactExecutionBatchNote
Low Risk
Mostly additive API and TypeScript typing changes; runtime caveat building logic is unchanged, with the main risk being potential type-level breaking changes for consumers relying on previous
CoreCaveatBuilderkey types.Overview
Adds a public
CaveatTypeenum (exported fromsrc/index.ts) to provide a type-safe alternative to string literals when selecting caveat/enforcer types.Updates
coreCaveatBuilder’s type map to accept both the existing string keys andCaveatTypeenum values (via a mapped type alias), and expands thecreateCaveatBuildertest suite to assert.addCaveat(CaveatType.*)produces the same caveat output as string-based usage.Written by Cursor Bugbot for commit 5327b00. This will update automatically on new commits. Configure here.