Skip to content

Conversation

@MoMannn
Copy link
Contributor

@MoMannn MoMannn commented Jan 20, 2026

📝 Description

Introduces a centralized ScopeType enum to replace scattered string literal constants used for scope type discrimination. This improves type safety and discoverability when configuring delegation permission scopes.

🔄 What Changed?

  • Added new ScopeType enum to constants.ts with all scope type values (Erc20TransferAmount, Erc20Streaming, Erc20PeriodTransfer, NativeTokenTransferAmount, NativeTokenStreaming, NativeTokenPeriodTransfer, Erc721Transfer, OwnershipTransfer, FunctionCall)
  • Exported ScopeType from the package's public API via index.ts
  • Updated all scope config type definitions to use ScopeType.X instead of typeof builderConstant
  • Migrated createCaveatBuilderFromScope switch cases to use ScopeType enum values
  • Updated all related test files to use the new ScopeType enum
  • Updated ScopeConfig type to be union of ScopeType enum and ScopeType enum string values

🚀 Why?

  • Improved discoverability: SDK consumers can now find all available scope types in one place (ScopeType enum) rather than hunting through individual builder files
  • Cleaner imports: Consumers no longer need to import string constants from deep builder paths; they can simply use ScopeType.Erc20TransferAmount etc.
  • Consistency: Aligns with existing patterns in the codebase where enums are used for similar purposes (Implementation, TransferWindow)
  • Better IDE support: Enum values provide autocomplete suggestions, making it easier to discover and use the correct scope type

By changing ScopeConfig to be a union of ScopeType enum and string literal values, the interface aligns with established viem conventions. viem commonly uses string literal unions for parameters, and developers in that ecosystem generally expect to pass string values directly. Supporting both the enum reference and its string value preserves backwards compatibility, reduces friction for existing users, and adds flexibility without detracting from the value of the enum-based API. See #137 for more details.

Effectively, this allows a caller to:

createDelegation({
  scope: ScopeType.FunctionCall,
  // ...
});

OR

createDelegation({
  scope: 'functionCall,
  // ...
});

🧪 How to Test?

Describe how to test these changes:

  • Manual testing steps:
  1. Use a scope builder
  • Automated tests added/updated
  • All existing tests pass

⚠️ Breaking Changes

List any breaking changes:

  • No breaking changes
  • [] Breaking changes (describe below):

📋 Checklist

Check off completed items:

  • Code follows the project's coding standards
  • Self-review completed
  • Documentation updated (if needed)
  • Tests added/updated
  • Changelog updated (if needed)
  • All CI checks pass

🔗 Related Issues

Link to related issues:
Closes #
Related to #

📚 Additional Notes

Any additional information, concerns, or context:


Note

Low Risk
Low risk: primarily type-system/API ergonomics changes around scope type discrimination, with only a small runtime cast/normalization in createCaveatBuilderFromScope that could affect behavior if invalid strings slip through.

Overview
Adds a centralized ScopeType enum (exported from the public API) and updates all scope config types to use ScopeType.* instead of scattered string/builder constants.

createCaveatBuilderFromScope now normalizes scopeConfig.type so callers can pass either the enum value or its string literal, while the internal switch consistently dispatches on ScopeType. Tests and the changelog are updated accordingly, including coverage for passing a string scope type.

Written by Cursor Bugbot for commit e65c06d. This will update automatically on new commits. Configure here.

@MoMannn MoMannn requested a review from a team as a code owner January 20, 2026 10:30
Copy link
Collaborator

@jeffsmale90 jeffsmale90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good. I've opened this PR #137 targeting this branch to introduce backwards compatibility. Have a look at the "Why" in there - I think we can get the benefits of this change, without breaking the established viem pattern of passing string union literals.

Lmk wyt.

Of note, this change will also need to be applied to the caveat configs. I've opened a ticket in our backlog.

Copy link
Collaborator

@jeffsmale90 jeffsmale90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I left a suggestion to change the CHANGELOG and updated the description to describe the change to ScopeConfig to allow string values.

Copy link
Member

@AyushBherwani1998 AyushBherwani1998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let'ss go! LGTM.

export const createCaveatBuilderFromScope = (
environment: SmartAccountsEnvironment,
scopeConfig: ScopeConfig,
) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return type on function eslint@typescript-eslint/explicit-function-return-type

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

jeffsmale90
jeffsmale90 previously approved these changes Feb 2, 2026
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Copy link
Collaborator

@jeffsmale90 jeffsmale90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@mj-kiwi mj-kiwi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go!

@jeffsmale90 jeffsmale90 merged commit 0444189 into main Feb 3, 2026
11 of 27 checks passed
@jeffsmale90 jeffsmale90 deleted the chore--scope-types branch February 3, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants