Skip to content

Commit fab0b5f

Browse files
authored
feat: add CaveatType enum and integrate into core caveat builder (#179)
* feat: add CaveatType enum and integrate into core caveat builder * feat: reintroduce CaveatType enum and update core caveat builder integration * feat: remove CaveatTypeParam type definition for simplification * feat: refactor CoreCaveatMap type definition for improved type resolution * fix: update import path for CaveatType in coreCaveatBuilder * feat: update CaveatMapLookup to use _CoreCaveatMap for improved type safety * feat: simplify CaveatMapLookup type definition for clarity * feat: remove unused import of Caveat from coreCaveatBuilder for cleaner code * feat: update CoreCaveatMap to directly reference _CoreCaveatMap for improved type clarity * feat: add tests for caveat builders using CaveatType enum for improved coverage * feat: rename _CoreCaveatMap to CoreCaveatMapByString for clarity and update CoreCaveatMap type definition
1 parent 75bdf60 commit fab0b5f

4 files changed

Lines changed: 484 additions & 2 deletions

File tree

packages/smart-accounts-kit/src/caveatBuilder/coreCaveatBuilder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ import {
8383
} from './specificActionERC20TransferBatchBuilder';
8484
import { timestamp, timestampBuilder } from './timestampBuilder';
8585
import { valueLte, valueLteBuilder } from './valueLteBuilder';
86+
import type { CaveatType } from '../constants';
8687

8788
// While we could derive CoreCaveatMap from the createCaveatBuilder function,
8889
// doing so would significantly complicate type resolution. By explicitly
8990
// declaring the return type of createCaveatBuilder, we ensure the caveat
9091
// map remains synchronized with the actual implementation.
91-
type CoreCaveatMap = {
92+
type CoreCaveatMapByString = {
9293
allowedMethods: typeof allowedMethodsBuilder;
9394
allowedTargets: typeof allowedTargetsBuilder;
9495
deployed: typeof deployedBuilder;
@@ -122,6 +123,10 @@ type CoreCaveatMap = {
122123
ownershipTransfer: typeof ownershipTransferBuilder;
123124
};
124125

126+
type CoreCaveatMap = CoreCaveatMapByString & {
127+
[K in CaveatType as `${K}`]: CoreCaveatMapByString[`${K}`];
128+
};
129+
125130
/**
126131
* A caveat builder type that includes all core caveat types pre-configured.
127132
* This type represents a fully configured caveat builder with all the standard

packages/smart-accounts-kit/src/constants.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,42 @@ export enum ScopeType {
5353
OwnershipTransfer = 'ownershipTransfer',
5454
FunctionCall = 'functionCall',
5555
}
56+
57+
/**
58+
* Caveat types for enforcer functions used in delegations.
59+
* Can be used when defining caveats either via CaveatBuilder.addCaveat
60+
* or in the caveats array in createDelegation.
61+
*/
62+
export enum CaveatType {
63+
AllowedMethods = 'allowedMethods',
64+
AllowedTargets = 'allowedTargets',
65+
Deployed = 'deployed',
66+
AllowedCalldata = 'allowedCalldata',
67+
Erc20BalanceChange = 'erc20BalanceChange',
68+
Erc721BalanceChange = 'erc721BalanceChange',
69+
Erc1155BalanceChange = 'erc1155BalanceChange',
70+
ValueLte = 'valueLte',
71+
LimitedCalls = 'limitedCalls',
72+
Id = 'id',
73+
Nonce = 'nonce',
74+
Timestamp = 'timestamp',
75+
BlockNumber = 'blockNumber',
76+
Erc20TransferAmount = 'erc20TransferAmount',
77+
Erc20Streaming = 'erc20Streaming',
78+
NativeTokenStreaming = 'nativeTokenStreaming',
79+
Erc721Transfer = 'erc721Transfer',
80+
NativeTokenTransferAmount = 'nativeTokenTransferAmount',
81+
NativeBalanceChange = 'nativeBalanceChange',
82+
Redeemer = 'redeemer',
83+
NativeTokenPayment = 'nativeTokenPayment',
84+
ArgsEqualityCheck = 'argsEqualityCheck',
85+
SpecificActionERC20TransferBatch = 'specificActionERC20TransferBatch',
86+
Erc20PeriodTransfer = 'erc20PeriodTransfer',
87+
NativeTokenPeriodTransfer = 'nativeTokenPeriodTransfer',
88+
ExactCalldataBatch = 'exactCalldataBatch',
89+
ExactCalldata = 'exactCalldata',
90+
ExactExecution = 'exactExecution',
91+
ExactExecutionBatch = 'exactExecutionBatch',
92+
MultiTokenPeriod = 'multiTokenPeriod',
93+
OwnershipTransfer = 'ownershipTransfer',
94+
}

packages/smart-accounts-kit/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ export {
3737
getSmartAccountsEnvironment,
3838
} from './smartAccountsEnvironment';
3939

40-
export { Implementation, TransferWindow, ScopeType } from './constants';
40+
export {
41+
Implementation,
42+
TransferWindow,
43+
ScopeType,
44+
CaveatType,
45+
} from './constants';
4146

4247
export { createExecution, ExecutionMode } from './executions';
4348

0 commit comments

Comments
 (0)