From f4d9fd9d73b3e3909036829ce85e3fa65cf8555c Mon Sep 17 00:00:00 2001 From: MoMannn Date: Tue, 20 Jan 2026 11:14:48 +0100 Subject: [PATCH 1/9] introduce scope types --- .../caveatBuilder/scope/erc20PeriodicScope.ts | 8 ++---- .../scope/erc20StreamingScope.ts | 8 ++---- .../caveatBuilder/scope/erc20TransferScope.ts | 8 ++---- .../src/caveatBuilder/scope/erc721Scope.ts | 8 ++---- .../caveatBuilder/scope/functionCallScope.ts | 3 +- .../src/caveatBuilder/scope/index.ts | 28 +++++++------------ .../scope/nativeTokenPeriodicScope.ts | 8 ++---- .../scope/nativeTokenStreamingScope.ts | 8 ++---- .../scope/nativeTokenTransferScope.ts | 8 ++---- .../src/caveatBuilder/scope/ownershipScope.ts | 8 ++---- packages/smart-accounts-kit/src/constants.ts | 16 +++++++++++ packages/smart-accounts-kit/src/index.ts | 2 +- .../delegationManagement.test.ts | 7 +++-- .../test/caveatBuilder/resolveCaveats.test.ts | 5 ++-- .../scope/erc20PeriodicScope.test.ts | 3 +- .../scope/erc20StreamingScope.test.ts | 3 +- .../scope/erc20TransferScope.test.ts | 3 +- .../caveatBuilder/scope/erc721Scope.test.ts | 7 +++-- .../scope/functionCallScope.test.ts | 11 ++++---- .../scope/nativeTokenPeriodicScope.test.ts | 5 ++-- .../scope/nativeTokenStreamingScope.test.ts | 7 +++-- .../scope/nativeTokenTransferScope.test.ts | 9 +++--- .../scope/ownershipScope.test.ts | 5 ++-- .../test/delegation.test.ts | 3 +- 24 files changed, 94 insertions(+), 87 deletions(-) diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts index 020a1ba0..9f1a1fdc 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts @@ -1,13 +1,11 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; -import type { - erc20PeriodTransfer, - Erc20PeriodTransferBuilderConfig, -} from '../erc20PeriodTransferBuilder'; +import type { Erc20PeriodTransferBuilderConfig } from '../erc20PeriodTransferBuilder'; export type Erc20PeriodicScopeConfig = { - type: typeof erc20PeriodTransfer; + type: ScopeType.Erc20PeriodTransfer; } & Erc20PeriodTransferBuilderConfig; /** diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts index 449ff608..b333185d 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts @@ -1,13 +1,11 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; -import type { - erc20Streaming, - Erc20StreamingBuilderConfig, -} from '../erc20StreamingBuilder'; +import type { Erc20StreamingBuilderConfig } from '../erc20StreamingBuilder'; export type Erc20StreamingScopeConfig = { - type: typeof erc20Streaming; + type: ScopeType.Erc20Streaming; } & Erc20StreamingBuilderConfig; /** diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts index 9d0ad2bb..fbb26b1f 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts @@ -1,13 +1,11 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; -import type { - erc20TransferAmount, - Erc20TransferAmountBuilderConfig, -} from '../erc20TransferAmountBuilder'; +import type { Erc20TransferAmountBuilderConfig } from '../erc20TransferAmountBuilder'; export type Erc20TransferScopeConfig = { - type: typeof erc20TransferAmount; + type: ScopeType.Erc20TransferAmount; } & Erc20TransferAmountBuilderConfig; /** diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts index 08921855..19e1b9fc 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts @@ -1,14 +1,12 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; -import type { - erc721Transfer, - Erc721TransferBuilderConfig, -} from '../erc721TransferBuilder'; +import type { Erc721TransferBuilderConfig } from '../erc721TransferBuilder'; export type Erc721ScopeBaseConfig = { - type: typeof erc721Transfer; + type: ScopeType.Erc721Transfer; }; export type Erc721ScopeConfig = Erc721ScopeBaseConfig & diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts index 2b863a92..6bb0c4cc 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts @@ -1,3 +1,4 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; @@ -9,7 +10,7 @@ import type { ExactCalldataBuilderConfig } from '../exactCalldataBuilder'; import type { ValueLteBuilderConfig } from '../valueLteBuilder'; type FunctionCallScopeBaseConfig = { - type: 'functionCall'; + type: ScopeType.FunctionCall; allowedCalldata?: AllowedCalldataBuilderConfig[]; exactCalldata?: ExactCalldataBuilderConfig; valueLte?: ValueLteBuilderConfig; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts index b5bbb02c..64b22f36 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts @@ -34,16 +34,8 @@ import { createOwnershipCaveatBuilder, type OwnershipScopeConfig, } from './ownershipScope'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; -// Import caveat builder name constants -import { erc20PeriodTransfer } from '../erc20PeriodTransferBuilder'; -import { erc20Streaming } from '../erc20StreamingBuilder'; -import { erc20TransferAmount } from '../erc20TransferAmountBuilder'; -import { erc721Transfer } from '../erc721TransferBuilder'; -import { nativeTokenPeriodTransfer } from '../nativeTokenPeriodTransferBuilder'; -import { nativeTokenStreaming } from '../nativeTokenStreamingBuilder'; -import { nativeTokenTransferAmount } from '../nativeTokenTransferAmountBuilder'; -import { ownershipTransfer } from '../ownershipTransferBuilder'; export type ScopeConfig = | Erc20TransferScopeConfig @@ -61,23 +53,23 @@ export const createCaveatBuilderFromScope = ( scopeConfig: ScopeConfig, ) => { switch (scopeConfig.type) { - case erc20TransferAmount: + case ScopeType.Erc20TransferAmount: return createErc20TransferCaveatBuilder(environment, scopeConfig); - case erc20Streaming: + case ScopeType.Erc20Streaming: return createErc20StreamingCaveatBuilder(environment, scopeConfig); - case erc20PeriodTransfer: + case ScopeType.Erc20PeriodTransfer: return createErc20PeriodicCaveatBuilder(environment, scopeConfig); - case nativeTokenTransferAmount: + case ScopeType.NativeTokenTransferAmount: return createNativeTokenTransferCaveatBuilder(environment, scopeConfig); - case nativeTokenStreaming: + case ScopeType.NativeTokenStreaming: return createNativeTokenStreamingCaveatBuilder(environment, scopeConfig); - case nativeTokenPeriodTransfer: + case ScopeType.NativeTokenPeriodTransfer: return createNativeTokenPeriodicCaveatBuilder(environment, scopeConfig); - case erc721Transfer: + case ScopeType.Erc721Transfer: return createErc721CaveatBuilder(environment, scopeConfig); - case ownershipTransfer: + case ScopeType.OwnershipTransfer: return createOwnershipCaveatBuilder(environment, scopeConfig); - case 'functionCall': + case ScopeType.FunctionCall: return createFunctionCallCaveatBuilder(environment, scopeConfig); default: // eslint-disable-next-line no-case-declarations diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts index aefc8010..d72daaa6 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts @@ -1,15 +1,13 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; import type { ExactCalldataBuilderConfig } from '../exactCalldataBuilder'; -import type { - nativeTokenPeriodTransfer, - NativeTokenPeriodTransferBuilderConfig, -} from '../nativeTokenPeriodTransferBuilder'; +import type { NativeTokenPeriodTransferBuilderConfig } from '../nativeTokenPeriodTransferBuilder'; export type NativeTokenPeriodicScopeConfig = { - type: typeof nativeTokenPeriodTransfer; + type: ScopeType.NativeTokenPeriodTransfer; allowedCalldata?: AllowedCalldataBuilderConfig[]; exactCalldata?: ExactCalldataBuilderConfig; } & NativeTokenPeriodTransferBuilderConfig; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts index 714ed506..3139bab3 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts @@ -1,15 +1,13 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; import type { ExactCalldataBuilderConfig } from '../exactCalldataBuilder'; -import type { - nativeTokenStreaming, - NativeTokenStreamingBuilderConfig, -} from '../nativeTokenStreamingBuilder'; +import type { NativeTokenStreamingBuilderConfig } from '../nativeTokenStreamingBuilder'; export type NativeTokenStreamingScopeConfig = { - type: typeof nativeTokenStreaming; + type: ScopeType.NativeTokenStreaming; allowedCalldata?: AllowedCalldataBuilderConfig[]; exactCalldata?: ExactCalldataBuilderConfig; } & NativeTokenStreamingBuilderConfig; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts index 43ff7bcd..82618526 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts @@ -1,15 +1,13 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; import type { ExactCalldataBuilderConfig } from '../exactCalldataBuilder'; -import type { - nativeTokenTransferAmount, - NativeTokenTransferAmountBuilderConfig, -} from '../nativeTokenTransferAmountBuilder'; +import type { NativeTokenTransferAmountBuilderConfig } from '../nativeTokenTransferAmountBuilder'; export type NativeTokenTransferScopeConfig = { - type: typeof nativeTokenTransferAmount; + type: ScopeType.NativeTokenTransferAmount; allowedCalldata?: AllowedCalldataBuilderConfig[]; exactCalldata?: ExactCalldataBuilderConfig; } & NativeTokenTransferAmountBuilderConfig; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts index c86697d4..2033d708 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts @@ -1,14 +1,12 @@ +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; -import type { - ownershipTransfer, - OwnershipTransferBuilderConfig, -} from '../ownershipTransferBuilder'; +import type { OwnershipTransferBuilderConfig } from '../ownershipTransferBuilder'; type OwnershipScopeBaseConfig = { - type: typeof ownershipTransfer; + type: ScopeType.OwnershipTransfer; }; export type OwnershipScopeConfig = OwnershipScopeBaseConfig & diff --git a/packages/smart-accounts-kit/src/constants.ts b/packages/smart-accounts-kit/src/constants.ts index 49aee0d0..11e9a2c9 100644 --- a/packages/smart-accounts-kit/src/constants.ts +++ b/packages/smart-accounts-kit/src/constants.ts @@ -37,3 +37,19 @@ export enum TransferWindow { Quarterly = 7776000, // 60 * 60 * 24 * 90 (seconds) Yearly = 31536000, // 60 * 60 * 24 * 365 (seconds) } + +/** + * Scope types for configuring delegation permissions. + * Used with createCaveatBuilderFromScope to specify the type of permission scope. + */ +export enum ScopeType { + Erc20TransferAmount = 'erc20TransferAmount', + Erc20Streaming = 'erc20Streaming', + Erc20PeriodTransfer = 'erc20PeriodTransfer', + NativeTokenTransferAmount = 'nativeTokenTransferAmount', + NativeTokenStreaming = 'nativeTokenStreaming', + NativeTokenPeriodTransfer = 'nativeTokenPeriodTransfer', + Erc721Transfer = 'erc721Transfer', + OwnershipTransfer = 'ownershipTransfer', + FunctionCall = 'functionCall', +} diff --git a/packages/smart-accounts-kit/src/index.ts b/packages/smart-accounts-kit/src/index.ts index f7b1c2ea..0c4dee8b 100644 --- a/packages/smart-accounts-kit/src/index.ts +++ b/packages/smart-accounts-kit/src/index.ts @@ -36,7 +36,7 @@ export { getSmartAccountsEnvironment, } from './smartAccountsEnvironment'; -export { Implementation, TransferWindow } from './constants'; +export { Implementation, TransferWindow, ScopeType } from './constants'; export { createExecution, ExecutionMode } from './executions'; diff --git a/packages/smart-accounts-kit/test/DelegationFramework/DelegationManager/delegationManagement.test.ts b/packages/smart-accounts-kit/test/DelegationFramework/DelegationManager/delegationManagement.test.ts index 83660ef9..3e7feb58 100644 --- a/packages/smart-accounts-kit/test/DelegationFramework/DelegationManager/delegationManagement.test.ts +++ b/packages/smart-accounts-kit/test/DelegationFramework/DelegationManager/delegationManagement.test.ts @@ -2,6 +2,7 @@ import { isHex } from 'viem'; import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'; import { describe, expect, it } from 'vitest'; +import { ScopeType } from '../../../src/constants'; import { createDelegation } from '../../../src/delegation'; import * as DelegationManager from '../../../src/DelegationFramework/DelegationManager'; import { ExecutionMode, createExecution } from '../../../src/executions'; @@ -87,7 +88,7 @@ describe('DelegationManager - Delegation Management', () => { from: alice.address, environment, scope: { - type: 'functionCall', + type: ScopeType.FunctionCall, targets: [alice.address], selectors: ['0x00000000'], }, @@ -112,7 +113,7 @@ describe('DelegationManager - Delegation Management', () => { from: alice.address, environment, scope: { - type: 'functionCall', + type: ScopeType.FunctionCall, targets: [alice.address], selectors: ['0x00000000'], }, @@ -137,7 +138,7 @@ describe('DelegationManager - Delegation Management', () => { from: alice.address, environment, scope: { - type: 'functionCall', + type: ScopeType.FunctionCall, targets: [alice.address], selectors: ['0x00000000'], }, diff --git a/packages/smart-accounts-kit/test/caveatBuilder/resolveCaveats.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/resolveCaveats.test.ts index 8bfd83db..82c9418a 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/resolveCaveats.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/resolveCaveats.test.ts @@ -5,6 +5,7 @@ import type { CoreCaveatConfiguration } from '../../src/caveatBuilder/coreCaveat import { createCaveatBuilder } from '../../src/caveatBuilder/coreCaveatBuilder'; import { resolveCaveats } from '../../src/caveatBuilder/resolveCaveats'; import type { ScopeConfig } from '../../src/caveatBuilder/scope'; +import { ScopeType } from '../../src/constants'; import type { Caveat, SmartAccountsEnvironment } from '../../src/types'; import { randomAddress } from '../utils'; @@ -32,7 +33,7 @@ describe('resolveCaveats', () => { }; const erc20Scope: ScopeConfig = { - type: 'erc20TransferAmount', + type: ScopeType.Erc20TransferAmount, tokenAddress: randomAddress(), maxAmount: 1000n, }; @@ -182,7 +183,7 @@ describe('resolveCaveats', () => { describe('scope', () => { it('should work with different scope types', () => { const erc721Scope: ScopeConfig = { - type: 'erc721Transfer', + type: ScopeType.Erc721Transfer, tokenAddress: randomAddress(), tokenId: 123n, }; diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20PeriodicScope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20PeriodicScope.test.ts index 00e5452e..e8690087 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20PeriodicScope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20PeriodicScope.test.ts @@ -3,6 +3,7 @@ import { describe, it, expect } from 'vitest'; import { createErc20PeriodicCaveatBuilder } from '../../../src/caveatBuilder/scope/erc20PeriodicScope'; import type { Erc20PeriodicScopeConfig } from '../../../src/caveatBuilder/scope/erc20PeriodicScope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -16,7 +17,7 @@ describe('createErc20PeriodicCaveatBuilder', () => { it('creates an ERC20 periodic transfer CaveatBuilder', () => { const config: Erc20PeriodicScopeConfig = { - type: 'erc20PeriodTransfer', + type: ScopeType.Erc20PeriodTransfer, tokenAddress: randomAddress(), periodAmount: 1000n, periodDuration: 1000, diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20StreamingScope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20StreamingScope.test.ts index 2d1d58ea..2b22ced0 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20StreamingScope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20StreamingScope.test.ts @@ -3,6 +3,7 @@ import { describe, it, expect } from 'vitest'; import { createErc20StreamingCaveatBuilder } from '../../../src/caveatBuilder/scope/erc20StreamingScope'; import type { Erc20StreamingScopeConfig } from '../../../src/caveatBuilder/scope/erc20StreamingScope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -16,7 +17,7 @@ describe('createErc20StreamingCaveatBuilder', () => { it('creates an ERC20 streaming CaveatBuilder', () => { const config: Erc20StreamingScopeConfig = { - type: 'erc20Streaming', + type: ScopeType.Erc20Streaming, tokenAddress: randomAddress(), initialAmount: 1000n, maxAmount: 10000n, diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20TransferScope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20TransferScope.test.ts index c644f9f0..40078b8f 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20TransferScope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/erc20TransferScope.test.ts @@ -3,6 +3,7 @@ import { describe, it, expect } from 'vitest'; import { createErc20TransferCaveatBuilder } from '../../../src/caveatBuilder/scope/erc20TransferScope'; import type { Erc20TransferScopeConfig } from '../../../src/caveatBuilder/scope/erc20TransferScope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -16,7 +17,7 @@ describe('createErc20TransferCaveatBuilder', () => { it('creates an ERC20 transfer CaveatBuilder', () => { const config: Erc20TransferScopeConfig = { - type: 'erc20TransferAmount', + type: ScopeType.Erc20TransferAmount, tokenAddress: randomAddress(), maxAmount: 1000n, }; diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/erc721Scope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/erc721Scope.test.ts index df110429..556fc24f 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/erc721Scope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/erc721Scope.test.ts @@ -3,6 +3,7 @@ import { describe, it, expect } from 'vitest'; import { createErc721CaveatBuilder } from '../../../src/caveatBuilder/scope/erc721Scope'; import type { Erc721ScopeConfig } from '../../../src/caveatBuilder/scope/erc721Scope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -15,7 +16,7 @@ describe('createErc721CaveatBuilder', () => { it('creates an ERC721 transfer CaveatBuilder', () => { const config: Erc721ScopeConfig = { - type: 'erc721Transfer', + type: ScopeType.Erc721Transfer, tokenAddress: randomAddress(), tokenId: 1n, }; @@ -37,7 +38,9 @@ describe('createErc721CaveatBuilder', () => { }); it('throws an error for invalid configuration', () => { - const config = { type: 'erc721Transfer' } as unknown as Erc721ScopeConfig; + const config = { + type: ScopeType.Erc721Transfer, + } as unknown as Erc721ScopeConfig; expect(() => createErc721CaveatBuilder(environment, config)).to.throw( 'Invalid ERC721 configuration', diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/functionCallScope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/functionCallScope.test.ts index 04040ddc..d4ca5257 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/functionCallScope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/functionCallScope.test.ts @@ -4,6 +4,7 @@ import { describe, it, expect } from 'vitest'; import { createFunctionCallCaveatBuilder } from '../../../src/caveatBuilder/scope/functionCallScope'; import type { FunctionCallScopeConfig } from '../../../src/caveatBuilder/scope/functionCallScope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -20,7 +21,7 @@ describe('createFunctionCallCaveatBuilder', () => { it('creates a Function Call CaveatBuilder', () => { const config: FunctionCallScopeConfig = { - type: 'functionCall', + type: ScopeType.FunctionCall, targets: [randomAddress()], selectors: ['0x12345678'], }; @@ -51,7 +52,7 @@ describe('createFunctionCallCaveatBuilder', () => { it('creates a Function Call CaveatBuilder with allowed calldata', () => { const allowedCalldata = { value: '0x12345678', startIndex: 0 } as const; const config: FunctionCallScopeConfig = { - type: 'functionCall', + type: ScopeType.FunctionCall, targets: [randomAddress()], selectors: ['0x12345678'], allowedCalldata: [allowedCalldata], @@ -91,7 +92,7 @@ describe('createFunctionCallCaveatBuilder', () => { it('creates a Function Call CaveatBuilder with exact calldata', () => { const exactCalldata = { calldata: '0x12345678' } as const; const config: FunctionCallScopeConfig = { - type: 'functionCall', + type: ScopeType.FunctionCall, targets: [randomAddress()], selectors: ['0x12345678'], exactCalldata, @@ -127,7 +128,7 @@ describe('createFunctionCallCaveatBuilder', () => { it('creates a Function Call CaveatBuilder with configured valueLte', () => { const config: FunctionCallScopeConfig = { - type: 'functionCall', + type: ScopeType.FunctionCall, targets: [randomAddress()], selectors: ['0x12345678'], valueLte: { maxValue: 123n }, @@ -158,7 +159,7 @@ describe('createFunctionCallCaveatBuilder', () => { it('throws an error for invalid configuration', () => { const config = { - type: 'functionCall', + type: ScopeType.FunctionCall, } as unknown as FunctionCallScopeConfig; expect(() => createFunctionCallCaveatBuilder(environment, config)).to.throw( diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenPeriodicScope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenPeriodicScope.test.ts index 3d386887..b30dc294 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenPeriodicScope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenPeriodicScope.test.ts @@ -3,6 +3,7 @@ import { describe, it, expect } from 'vitest'; import { createNativeTokenPeriodicCaveatBuilder } from '../../../src/caveatBuilder/scope/nativeTokenPeriodicScope'; import type { NativeTokenPeriodicScopeConfig } from '../../../src/caveatBuilder/scope/nativeTokenPeriodicScope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -17,7 +18,7 @@ describe('createNativeTokenPeriodicCaveatBuilder', () => { it('creates a native token periodic transfer CaveatBuilder', () => { const config: NativeTokenPeriodicScopeConfig = { - type: 'nativeTokenPeriodTransfer', + type: ScopeType.NativeTokenPeriodTransfer, periodAmount: 1000n, periodDuration: 1000, startDate: Math.floor(Date.now() / 1000), @@ -50,7 +51,7 @@ describe('createNativeTokenPeriodicCaveatBuilder', () => { it('creates a native token periodic transfer CaveatBuilder with empty allowedCalldata array (should fall back to default)', () => { const config: NativeTokenPeriodicScopeConfig = { - type: 'nativeTokenPeriodTransfer', + type: ScopeType.NativeTokenPeriodTransfer, periodAmount: 1000n, periodDuration: 1000, startDate: Math.floor(Date.now() / 1000), diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenStreamingScope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenStreamingScope.test.ts index 260b7867..b0dba84d 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenStreamingScope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenStreamingScope.test.ts @@ -3,6 +3,7 @@ import { describe, it, expect } from 'vitest'; import { createNativeTokenStreamingCaveatBuilder } from '../../../src/caveatBuilder/scope/nativeTokenStreamingScope'; import type { NativeTokenStreamingScopeConfig } from '../../../src/caveatBuilder/scope/nativeTokenStreamingScope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -17,7 +18,7 @@ describe('createNativeTokenStreamingCaveatBuilder', () => { it('creates a native token streaming CaveatBuilder with default empty calldata', () => { const config: NativeTokenStreamingScopeConfig = { - type: 'nativeTokenStreaming', + type: ScopeType.NativeTokenStreaming, initialAmount: 1000n, maxAmount: 10000n, amountPerSecond: 1n, @@ -52,7 +53,7 @@ describe('createNativeTokenStreamingCaveatBuilder', () => { it('creates a native token streaming CaveatBuilder with empty allowedCalldata array (should fall back to default)', () => { const config: NativeTokenStreamingScopeConfig = { - type: 'nativeTokenStreaming', + type: ScopeType.NativeTokenStreaming, initialAmount: 1000n, maxAmount: 10000n, amountPerSecond: 1n, @@ -88,7 +89,7 @@ describe('createNativeTokenStreamingCaveatBuilder', () => { it('creates a native token streaming CaveatBuilder with allowedCalldata', () => { const config: NativeTokenStreamingScopeConfig = { - type: 'nativeTokenStreaming', + type: ScopeType.NativeTokenStreaming, initialAmount: 1000n, maxAmount: 10000n, amountPerSecond: 1n, diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenTransferScope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenTransferScope.test.ts index 23f6891a..e0ef1043 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenTransferScope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/nativeTokenTransferScope.test.ts @@ -3,6 +3,7 @@ import { describe, it, expect } from 'vitest'; import { createNativeTokenTransferCaveatBuilder } from '../../../src/caveatBuilder/scope/nativeTokenTransferScope'; import type { NativeTokenTransferScopeConfig } from '../../../src/caveatBuilder/scope/nativeTokenTransferScope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -17,7 +18,7 @@ describe('createNativeTokenTransferCaveatBuilder', () => { it('creates a native token transfer CaveatBuilder with default empty calldata', () => { const config: NativeTokenTransferScopeConfig = { - type: 'nativeTokenTransferAmount', + type: ScopeType.NativeTokenTransferAmount, maxAmount: 1000n, }; @@ -44,7 +45,7 @@ describe('createNativeTokenTransferCaveatBuilder', () => { it('creates a native token transfer CaveatBuilder with exact calldata', () => { const config: NativeTokenTransferScopeConfig = { - type: 'nativeTokenTransferAmount', + type: ScopeType.NativeTokenTransferAmount, maxAmount: 1000n, exactCalldata: { calldata: '0x1234abcd', @@ -74,7 +75,7 @@ describe('createNativeTokenTransferCaveatBuilder', () => { it('creates a native token transfer CaveatBuilder with empty allowedCalldata array (should fall back to default)', () => { const config: NativeTokenTransferScopeConfig = { - type: 'nativeTokenTransferAmount', + type: ScopeType.NativeTokenTransferAmount, maxAmount: 1000n, allowedCalldata: [], // Empty array should trigger fallback to default exactCalldata }; @@ -102,7 +103,7 @@ describe('createNativeTokenTransferCaveatBuilder', () => { it('creates a native token transfer CaveatBuilder with allowed calldata', () => { const config: NativeTokenTransferScopeConfig = { - type: 'nativeTokenTransferAmount', + type: ScopeType.NativeTokenTransferAmount, maxAmount: 1000n, allowedCalldata: [ { diff --git a/packages/smart-accounts-kit/test/caveatBuilder/scope/ownershipScope.test.ts b/packages/smart-accounts-kit/test/caveatBuilder/scope/ownershipScope.test.ts index 388edfda..80efa578 100644 --- a/packages/smart-accounts-kit/test/caveatBuilder/scope/ownershipScope.test.ts +++ b/packages/smart-accounts-kit/test/caveatBuilder/scope/ownershipScope.test.ts @@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest'; import { createOwnershipCaveatBuilder } from '../../../src/caveatBuilder/scope/ownershipScope'; import type { OwnershipScopeConfig } from '../../../src/caveatBuilder/scope/ownershipScope'; +import { ScopeType } from '../../../src/constants'; import type { SmartAccountsEnvironment } from '../../../src/types'; import { randomAddress } from '../../utils'; @@ -14,7 +15,7 @@ describe('createOwnershipTransferCaveatBuilder', () => { it('creates an Ownership Transfer CaveatBuilder', () => { const config: OwnershipScopeConfig = { - type: 'ownershipTransfer', + type: ScopeType.OwnershipTransfer, contractAddress: randomAddress(), }; @@ -33,7 +34,7 @@ describe('createOwnershipTransferCaveatBuilder', () => { it('throws an error for invalid configuration', () => { const config = { - type: 'ownershipTransfer', + type: ScopeType.OwnershipTransfer, } as unknown as OwnershipScopeConfig; expect(() => createOwnershipCaveatBuilder(environment, config)).to.throw( diff --git a/packages/smart-accounts-kit/test/delegation.test.ts b/packages/smart-accounts-kit/test/delegation.test.ts index c6862aef..55d0a926 100644 --- a/packages/smart-accounts-kit/test/delegation.test.ts +++ b/packages/smart-accounts-kit/test/delegation.test.ts @@ -2,6 +2,7 @@ import { getAddress, type Address, type Hex } from 'viem'; import { describe, it, expect } from 'vitest'; import { randomAddress } from './utils'; +import { ScopeType } from '../src/constants'; import { type DelegationStruct, ROOT_AUTHORITY, @@ -27,7 +28,7 @@ const mockSignature = '0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890' as const; const erc20Scope = { - type: 'erc20TransferAmount', + type: ScopeType.Erc20TransferAmount, tokenAddress: '0x1234567890123456789012345678901234567890', maxAmount: 100n, } as const; From e1e7a463c53dc1123b9c0603b3f35193715229e8 Mon Sep 17 00:00:00 2001 From: MoMannn Date: Tue, 20 Jan 2026 11:25:54 +0100 Subject: [PATCH 2/9] update imports --- .../src/caveatBuilder/scope/erc20PeriodicScope.ts | 2 +- .../src/caveatBuilder/scope/erc20StreamingScope.ts | 2 +- .../src/caveatBuilder/scope/erc20TransferScope.ts | 2 +- .../src/caveatBuilder/scope/erc721Scope.ts | 2 +- .../src/caveatBuilder/scope/functionCallScope.ts | 2 +- packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts | 5 +++-- .../src/caveatBuilder/scope/nativeTokenPeriodicScope.ts | 2 +- .../src/caveatBuilder/scope/nativeTokenStreamingScope.ts | 2 +- .../src/caveatBuilder/scope/nativeTokenTransferScope.ts | 2 +- .../src/caveatBuilder/scope/ownershipScope.ts | 2 +- 10 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts index 9f1a1fdc..3a7c3f60 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts index b333185d..af75aec1 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts index fbb26b1f..6b7a8db0 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts index 19e1b9fc..67823cc7 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import { createCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts index 6bb0c4cc..9fbbb421 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts index 64b22f36..2cfb5011 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts @@ -1,3 +1,6 @@ +import { ScopeType } from '../../constants'; +import type { SmartAccountsEnvironment } from '../../types'; + import { type Erc20PeriodicScopeConfig, createErc20PeriodicCaveatBuilder, @@ -34,8 +37,6 @@ import { createOwnershipCaveatBuilder, type OwnershipScopeConfig, } from './ownershipScope'; -import { ScopeType } from '../../constants'; -import type { SmartAccountsEnvironment } from '../../types'; export type ScopeConfig = | Erc20TransferScopeConfig diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts index d72daaa6..b86a4f41 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts index 3139bab3..eed56dfc 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts index 82618526..8ead0dca 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts index 2033d708..0c01d055 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts @@ -1,4 +1,4 @@ -import type { ScopeType } from '../../constants'; +import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import { createCaveatBuilder } from '../coreCaveatBuilder'; From c0a3000b3315c14dfec5dc4f21912a610478c7ed Mon Sep 17 00:00:00 2001 From: MoMannn Date: Tue, 20 Jan 2026 11:31:00 +0100 Subject: [PATCH 3/9] update changelog --- packages/smart-accounts-kit/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/smart-accounts-kit/CHANGELOG.md b/packages/smart-accounts-kit/CHANGELOG.md index 0b470a8f..b371a2d7 100644 --- a/packages/smart-accounts-kit/CHANGELOG.md +++ b/packages/smart-accounts-kit/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- **Breaking** Replace scope type strings with ScopeType enum ([#133](https://github.com/MetaMask/smart-accounts-kit/pull/133)) + ## [0.4.0-beta.0] ### Added From f27ef007ddee4ccd0716b71b741baa3ef1604c49 Mon Sep 17 00:00:00 2001 From: MoMannn Date: Tue, 20 Jan 2026 11:56:27 +0100 Subject: [PATCH 4/9] linter fixes --- .../src/caveatBuilder/scope/erc20PeriodicScope.ts | 2 +- .../src/caveatBuilder/scope/erc20StreamingScope.ts | 2 +- .../src/caveatBuilder/scope/erc20TransferScope.ts | 2 +- .../src/caveatBuilder/scope/erc721Scope.ts | 2 +- .../src/caveatBuilder/scope/functionCallScope.ts | 2 +- packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts | 5 ++--- .../src/caveatBuilder/scope/nativeTokenPeriodicScope.ts | 2 +- .../src/caveatBuilder/scope/nativeTokenStreamingScope.ts | 2 +- .../src/caveatBuilder/scope/nativeTokenTransferScope.ts | 2 +- .../src/caveatBuilder/scope/ownershipScope.ts | 2 +- 10 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts index 3a7c3f60..9f1a1fdc 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20PeriodicScope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts index af75aec1..b333185d 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20StreamingScope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts index 6b7a8db0..fbb26b1f 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc20TransferScope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { createCaveatBuilder } from '../coreCaveatBuilder'; import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts index 67823cc7..19e1b9fc 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/erc721Scope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import { createCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts index 9fbbb421..6bb0c4cc 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/functionCallScope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts index 2cfb5011..64b22f36 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts @@ -1,6 +1,3 @@ -import { ScopeType } from '../../constants'; -import type { SmartAccountsEnvironment } from '../../types'; - import { type Erc20PeriodicScopeConfig, createErc20PeriodicCaveatBuilder, @@ -37,6 +34,8 @@ import { createOwnershipCaveatBuilder, type OwnershipScopeConfig, } from './ownershipScope'; +import { ScopeType } from '../../constants'; +import type { SmartAccountsEnvironment } from '../../types'; export type ScopeConfig = | Erc20TransferScopeConfig diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts index b86a4f41..d72daaa6 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenPeriodicScope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts index eed56dfc..3139bab3 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenStreamingScope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts index 8ead0dca..82618526 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/nativeTokenTransferScope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import type { AllowedCalldataBuilderConfig } from '../allowedCalldataBuilder'; import { createCaveatBuilder } from '../coreCaveatBuilder'; diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts index 0c01d055..2033d708 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/ownershipScope.ts @@ -1,4 +1,4 @@ -import { ScopeType } from '../../constants'; +import type { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; import { hasProperties } from '../../utils'; import { createCaveatBuilder } from '../coreCaveatBuilder'; From 9a2e7dc8af42210d357db12d6e94fed23181460f Mon Sep 17 00:00:00 2001 From: jeffsmale90 <6363749+jeffsmale90@users.noreply.github.com> Date: Thu, 29 Jan 2026 22:09:23 +1300 Subject: [PATCH 5/9] Update ScopeConfig type to accept string 'type' parameter (#137) --- .../src/caveatBuilder/scope/index.ts | 65 +++++++++++++++---- .../test/delegation.test.ts | 22 ++++++- 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts index 64b22f36..a09a3805 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts @@ -37,7 +37,16 @@ import { import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; -export type ScopeConfig = +// We want to allow the scope `type` to be passed as either an enum reference, +// or the enum's string value this generic accepts a union of scope configs, and +// converts them to an identical union except the `type` parameter is converted +// to a union of `ScopeType.XXXX | `${ScopeType.XXXX}`. +export type ConvertScopeConfigsToInputs = + T extends { type: ScopeType } + ? Omit & { type: T['type'] | `${T['type']}` } + : never; + +type ScopeConfigBase = | Erc20TransferScopeConfig | Erc20StreamingScopeConfig | Erc20PeriodicScopeConfig @@ -48,32 +57,64 @@ export type ScopeConfig = | OwnershipScopeConfig | FunctionCallScopeConfig; +export type ScopeConfig = ConvertScopeConfigsToInputs; + +const normalizeScopeConfig = (config: ScopeConfig): ScopeConfigBase => { + return { + ...config, + type: config.type as ScopeType, + } as ScopeConfigBase; +}; + export const createCaveatBuilderFromScope = ( environment: SmartAccountsEnvironment, scopeConfig: ScopeConfig, ) => { - switch (scopeConfig.type) { + const normalizedScopeConfig = normalizeScopeConfig(scopeConfig); + + switch (normalizedScopeConfig.type) { case ScopeType.Erc20TransferAmount: - return createErc20TransferCaveatBuilder(environment, scopeConfig); + return createErc20TransferCaveatBuilder( + environment, + normalizedScopeConfig, + ); case ScopeType.Erc20Streaming: - return createErc20StreamingCaveatBuilder(environment, scopeConfig); + return createErc20StreamingCaveatBuilder( + environment, + normalizedScopeConfig, + ); case ScopeType.Erc20PeriodTransfer: - return createErc20PeriodicCaveatBuilder(environment, scopeConfig); + return createErc20PeriodicCaveatBuilder( + environment, + normalizedScopeConfig, + ); case ScopeType.NativeTokenTransferAmount: - return createNativeTokenTransferCaveatBuilder(environment, scopeConfig); + return createNativeTokenTransferCaveatBuilder( + environment, + normalizedScopeConfig, + ); case ScopeType.NativeTokenStreaming: - return createNativeTokenStreamingCaveatBuilder(environment, scopeConfig); + return createNativeTokenStreamingCaveatBuilder( + environment, + normalizedScopeConfig, + ); case ScopeType.NativeTokenPeriodTransfer: - return createNativeTokenPeriodicCaveatBuilder(environment, scopeConfig); + return createNativeTokenPeriodicCaveatBuilder( + environment, + normalizedScopeConfig, + ); case ScopeType.Erc721Transfer: - return createErc721CaveatBuilder(environment, scopeConfig); + return createErc721CaveatBuilder(environment, normalizedScopeConfig); case ScopeType.OwnershipTransfer: - return createOwnershipCaveatBuilder(environment, scopeConfig); + return createOwnershipCaveatBuilder(environment, normalizedScopeConfig); case ScopeType.FunctionCall: - return createFunctionCallCaveatBuilder(environment, scopeConfig); + return createFunctionCallCaveatBuilder( + environment, + normalizedScopeConfig, + ); default: // eslint-disable-next-line no-case-declarations - const exhaustivenessCheck: never = scopeConfig; + const exhaustivenessCheck: never = normalizedScopeConfig; throw new Error( `Invalid scope type: ${(exhaustivenessCheck as { type: string }).type}`, ); diff --git a/packages/smart-accounts-kit/test/delegation.test.ts b/packages/smart-accounts-kit/test/delegation.test.ts index 55d0a926..7e98e5e4 100644 --- a/packages/smart-accounts-kit/test/delegation.test.ts +++ b/packages/smart-accounts-kit/test/delegation.test.ts @@ -166,6 +166,24 @@ describe('resolveAuthority', () => { }); describe('createDelegation', () => { + it('creates a delegation with a scope type as a string', () => { + const result = createDelegation({ + environment: smartAccountEnvironment, + scope: { ...erc20Scope, type: 'erc20TransferAmount' }, + to: mockDelegate, + from: mockDelegator, + }); + + expect(result).to.deep.equal({ + delegate: mockDelegate, + delegator: mockDelegator, + authority: ROOT_AUTHORITY, + caveats: [...erc20ScopeCaveats], + salt: '0x', + signature: '0x', + }); + }); + it('should create a basic delegation with root authority', () => { const result = createDelegation({ environment: smartAccountEnvironment, @@ -178,9 +196,9 @@ describe('createDelegation', () => { expect(result).to.deep.equal({ delegate: mockDelegate, delegator: mockDelegator, - authority: ROOT_AUTHORITY as Hex, + authority: ROOT_AUTHORITY, caveats: [...erc20ScopeCaveats, mockCaveat], - salt: '0x' as Hex, + salt: '0x', signature: '0x', }); }); From 776e19d2b294c5a713d059569e481587b22013f5 Mon Sep 17 00:00:00 2001 From: Jeff Smale <6363749+jeffsmale90@users.noreply.github.com> Date: Fri, 30 Jan 2026 08:39:39 +1300 Subject: [PATCH 6/9] Update new test to align with updated default salt value --- packages/smart-accounts-kit/test/delegation.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smart-accounts-kit/test/delegation.test.ts b/packages/smart-accounts-kit/test/delegation.test.ts index 223bcea7..55999de2 100644 --- a/packages/smart-accounts-kit/test/delegation.test.ts +++ b/packages/smart-accounts-kit/test/delegation.test.ts @@ -179,7 +179,7 @@ describe('createDelegation', () => { delegator: mockDelegator, authority: ROOT_AUTHORITY, caveats: [...erc20ScopeCaveats], - salt: '0x', + salt: '0x00', signature: '0x', }); }); From 0d3d2d31b739c03954f6bb7ec90d58c60c411655 Mon Sep 17 00:00:00 2001 From: jeffsmale90 <6363749+jeffsmale90@users.noreply.github.com> Date: Tue, 3 Feb 2026 08:43:30 +1300 Subject: [PATCH 7/9] Update packages/smart-accounts-kit/CHANGELOG.md --- packages/smart-accounts-kit/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smart-accounts-kit/CHANGELOG.md b/packages/smart-accounts-kit/CHANGELOG.md index 8e4adb34..3eee26e8 100644 --- a/packages/smart-accounts-kit/CHANGELOG.md +++ b/packages/smart-accounts-kit/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- **Breaking** Replace scope type strings with ScopeType enum ([#133](https://github.com/MetaMask/smart-accounts-kit/pull/133)) +- Allow scope type to be specified either as `ScopeType` enum, or string literal ([#133](https://github.com/MetaMask/smart-accounts-kit/pull/133)) ## [0.4.0-beta.1] From 0ba7b85d803d73ff27ed14bf907a1c84720c619c Mon Sep 17 00:00:00 2001 From: Jeff Smale <6363749+jeffsmale90@users.noreply.github.com> Date: Tue, 3 Feb 2026 08:45:47 +1300 Subject: [PATCH 8/9] Add explicit return type for createCaveatBuilderFromScope --- packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts index a09a3805..2a33c66b 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts @@ -36,6 +36,7 @@ import { } from './ownershipScope'; import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; +import { CoreCaveatBuilder } from '../coreCaveatBuilder'; // We want to allow the scope `type` to be passed as either an enum reference, // or the enum's string value this generic accepts a union of scope configs, and @@ -69,7 +70,7 @@ const normalizeScopeConfig = (config: ScopeConfig): ScopeConfigBase => { export const createCaveatBuilderFromScope = ( environment: SmartAccountsEnvironment, scopeConfig: ScopeConfig, -) => { +): CoreCaveatBuilder => { const normalizedScopeConfig = normalizeScopeConfig(scopeConfig); switch (normalizedScopeConfig.type) { From e65c06da3abc2bfc7c735704da73244bc078d5d0 Mon Sep 17 00:00:00 2001 From: Jeff Smale <6363749+jeffsmale90@users.noreply.github.com> Date: Tue, 3 Feb 2026 08:54:50 +1300 Subject: [PATCH 9/9] Type import --- packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts index 2a33c66b..a53debb1 100644 --- a/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts +++ b/packages/smart-accounts-kit/src/caveatBuilder/scope/index.ts @@ -36,7 +36,7 @@ import { } from './ownershipScope'; import { ScopeType } from '../../constants'; import type { SmartAccountsEnvironment } from '../../types'; -import { CoreCaveatBuilder } from '../coreCaveatBuilder'; +import type { CoreCaveatBuilder } from '../coreCaveatBuilder'; // We want to allow the scope `type` to be passed as either an enum reference, // or the enum's string value this generic accepts a union of scope configs, and