@boostxyz/sdk 0.0.0-alpha.8 → 1.1.0-alpha.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Actions/Action.cjs +1 -1
- package/dist/Actions/Action.cjs.map +1 -1
- package/dist/Actions/Action.js +7 -7
- package/dist/Actions/ContractAction.d.ts +57 -14
- package/dist/Actions/ContractAction.d.ts.map +1 -1
- package/dist/Actions/ERC721MintAction.d.ts +50 -23
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.cjs +1 -1
- package/dist/Actions/EventAction.cjs.map +1 -1
- package/dist/Actions/EventAction.d.ts +420 -45
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +15 -225
- package/dist/Actions/EventAction.js.map +1 -1
- package/dist/AllowLists/AllowList.cjs +1 -1
- package/dist/AllowLists/AllowList.cjs.map +1 -1
- package/dist/AllowLists/AllowList.d.ts +6 -4
- package/dist/AllowLists/AllowList.d.ts.map +1 -1
- package/dist/AllowLists/AllowList.js +45 -23
- package/dist/AllowLists/AllowList.js.map +1 -1
- package/dist/AllowLists/OpenAllowList.d.ts +423 -0
- package/dist/AllowLists/OpenAllowList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +1 -1
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -1
- package/dist/AllowLists/SimpleAllowList.d.ts +123 -39
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleAllowList.js +75 -76
- package/dist/AllowLists/SimpleAllowList.js.map +1 -1
- package/dist/AllowLists/SimpleDenyList.cjs +1 -1
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -1
- package/dist/AllowLists/SimpleDenyList.d.ts +234 -13
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleDenyList.js +11 -200
- package/dist/AllowLists/SimpleDenyList.js.map +1 -1
- package/dist/Auth/PassthroughAuth.cjs +1 -1
- package/dist/Auth/PassthroughAuth.cjs.map +1 -1
- package/dist/Auth/PassthroughAuth.js +4 -4
- package/dist/Auth/PassthroughAuth.js.map +1 -1
- package/dist/Boost.cjs +1 -1
- package/dist/Boost.cjs.map +1 -1
- package/dist/Boost.d.ts +105 -14
- package/dist/Boost.d.ts.map +1 -1
- package/dist/Boost.js +137 -5
- package/dist/Boost.js.map +1 -1
- package/dist/BoostCore-BVZExPPu.js +1462 -0
- package/dist/BoostCore-BVZExPPu.js.map +1 -0
- package/dist/BoostCore-D-E-cnGI.cjs +3 -0
- package/dist/BoostCore-D-E-cnGI.cjs.map +1 -0
- package/dist/BoostCore.cjs +1 -2
- package/dist/BoostCore.cjs.map +1 -1
- package/dist/BoostCore.d.ts +759 -82
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +29 -1148
- package/dist/BoostCore.js.map +1 -1
- package/dist/BoostRegistry.cjs +1 -1
- package/dist/BoostRegistry.cjs.map +1 -1
- package/dist/BoostRegistry.d.ts +83 -28
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +170 -93
- package/dist/BoostRegistry.js.map +1 -1
- package/dist/Budgets/Budget.cjs +1 -1
- package/dist/Budgets/Budget.cjs.map +1 -1
- package/dist/Budgets/Budget.d.ts.map +1 -1
- package/dist/Budgets/Budget.js +2 -2
- package/dist/Budgets/Budget.js.map +1 -1
- package/dist/Budgets/ManagedBudget.cjs +1 -1
- package/dist/Budgets/ManagedBudget.cjs.map +1 -1
- package/dist/Budgets/ManagedBudget.d.ts +112 -192
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +89 -290
- package/dist/Budgets/ManagedBudget.js.map +1 -1
- package/dist/Budgets/VestingBudget.d.ts +277 -91
- package/dist/Budgets/VestingBudget.d.ts.map +1 -1
- package/dist/Deployable/Contract.cjs +1 -1
- package/dist/Deployable/Contract.cjs.map +1 -1
- package/dist/Deployable/Contract.d.ts +4 -5
- package/dist/Deployable/Contract.d.ts.map +1 -1
- package/dist/Deployable/Contract.js +6 -8
- package/dist/Deployable/Contract.js.map +1 -1
- package/dist/Deployable/Deployable.cjs.map +1 -1
- package/dist/Deployable/Deployable.d.ts +1 -1
- package/dist/Deployable/Deployable.d.ts.map +1 -1
- package/dist/Deployable/Deployable.js +3 -5
- package/dist/Deployable/Deployable.js.map +1 -1
- package/dist/Deployable/DeployableTarget.cjs +1 -1
- package/dist/Deployable/DeployableTarget.cjs.map +1 -1
- package/dist/Deployable/DeployableTarget.d.ts +13 -13
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -1
- package/dist/Deployable/DeployableTarget.js +30 -27
- package/dist/Deployable/DeployableTarget.js.map +1 -1
- package/dist/Deployable/DeployableTargetWithRBAC.cjs +2 -0
- package/dist/Deployable/DeployableTargetWithRBAC.cjs.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts +179 -0
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.js +222 -0
- package/dist/Deployable/DeployableTargetWithRBAC.js.map +1 -0
- package/dist/EventAction-BZt5cjbe.cjs +2 -0
- package/dist/EventAction-BZt5cjbe.cjs.map +1 -0
- package/dist/EventAction-C_-hJXWm.js +1541 -0
- package/dist/EventAction-C_-hJXWm.js.map +1 -0
- package/dist/Incentive-BhHaK3PZ.cjs +2 -0
- package/dist/Incentive-BhHaK3PZ.cjs.map +1 -0
- package/dist/Incentive-Cqg1w6wD.js +312 -0
- package/dist/Incentive-Cqg1w6wD.js.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +1 -1
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -1
- package/dist/Incentives/AllowListIncentive.d.ts +73 -21
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +61 -36
- package/dist/Incentives/AllowListIncentive.js.map +1 -1
- package/dist/Incentives/CGDAIncentive.cjs +1 -1
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -1
- package/dist/Incentives/CGDAIncentive.d.ts +323 -26
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +73 -39
- package/dist/Incentives/CGDAIncentive.js.map +1 -1
- package/dist/Incentives/ERC1155Incentive.d.ts +291 -43
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.cjs +1 -1
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -1
- package/dist/Incentives/ERC20Incentive.d.ts +278 -33
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +79 -47
- package/dist/Incentives/ERC20Incentive.js.map +1 -1
- package/dist/{Budgets/SimpleBudget.d.ts → Incentives/ERC20VariableCriteriaIncentive.d.ts} +346 -420
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +271 -32
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.cjs +1 -1
- package/dist/Incentives/Incentive.cjs.map +1 -1
- package/dist/Incentives/Incentive.d.ts +4 -4
- package/dist/Incentives/Incentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.js +16 -280
- package/dist/Incentives/Incentive.js.map +1 -1
- package/dist/Incentives/PointsIncentive.cjs +1 -1
- package/dist/Incentives/PointsIncentive.cjs.map +1 -1
- package/dist/Incentives/PointsIncentive.d.ts +89 -23
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
- package/dist/Incentives/PointsIncentive.js +66 -36
- package/dist/Incentives/PointsIncentive.js.map +1 -1
- package/dist/SimpleDenyList-BUR17Tt1.cjs +2 -0
- package/dist/SimpleDenyList-BUR17Tt1.cjs.map +1 -0
- package/dist/SimpleDenyList-CGaWjuld.js +132 -0
- package/dist/SimpleDenyList-CGaWjuld.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +1 -1
- package/dist/Validators/SignerValidator.cjs.map +1 -1
- package/dist/Validators/SignerValidator.d.ts +310 -17
- package/dist/Validators/SignerValidator.d.ts.map +1 -1
- package/dist/Validators/SignerValidator.js +164 -36
- package/dist/Validators/SignerValidator.js.map +1 -1
- package/dist/Validators/Validator.cjs +1 -1
- package/dist/Validators/Validator.cjs.map +1 -1
- package/dist/Validators/Validator.d.ts +1 -1
- package/dist/Validators/Validator.js +2 -2
- package/dist/Validators/Validator.js.map +1 -1
- package/dist/claiming.cjs +2 -0
- package/dist/claiming.cjs.map +1 -0
- package/dist/claiming.d.ts +43 -0
- package/dist/claiming.d.ts.map +1 -0
- package/dist/claiming.js +17 -0
- package/dist/claiming.js.map +1 -0
- package/dist/componentInterfaces-BBCFkrZv.js +14 -0
- package/dist/componentInterfaces-BBCFkrZv.js.map +1 -0
- package/dist/componentInterfaces-DRI_dQ-P.cjs +2 -0
- package/dist/componentInterfaces-DRI_dQ-P.cjs.map +1 -0
- package/dist/deployments-DVXioW2i.cjs +2 -0
- package/dist/deployments-DVXioW2i.cjs.map +1 -0
- package/dist/deployments-oykLv3_Z.js +43 -0
- package/dist/deployments-oykLv3_Z.js.map +1 -0
- package/dist/deployments.json +44 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +257 -21
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +183 -26
- package/dist/errors.js.map +1 -1
- package/dist/{generated-Cbv8zFkf.js → generated-CKt2yCQd.js} +3615 -1868
- package/dist/generated-CKt2yCQd.js.map +1 -0
- package/dist/generated-CyTNlOwM.cjs +3 -0
- package/dist/generated-CyTNlOwM.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +143 -126
- package/dist/index.js.map +1 -1
- package/dist/transfers.cjs +2 -0
- package/dist/transfers.cjs.map +1 -0
- package/dist/transfers.d.ts +198 -0
- package/dist/transfers.d.ts.map +1 -0
- package/dist/transfers.js +84 -0
- package/dist/transfers.js.map +1 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +25 -1380
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +36 -648
- package/dist/utils.js.map +1 -1
- package/package.json +34 -10
- package/src/Actions/Action.test.ts +19 -17
- package/src/Actions/ContractAction.test.ts +14 -16
- package/src/Actions/ContractAction.ts +84 -22
- package/src/Actions/ERC721MintAction.test.ts +8 -8
- package/src/Actions/ERC721MintAction.ts +83 -30
- package/src/Actions/EventAction.test.ts +759 -113
- package/src/Actions/EventAction.ts +991 -116
- package/src/AllowLists/AllowList.test.ts +7 -7
- package/src/AllowLists/AllowList.ts +5 -3
- package/src/AllowLists/OpenAllowList.test.ts +40 -0
- package/src/AllowLists/OpenAllowList.ts +45 -0
- package/src/AllowLists/SimpleAllowList.test.ts +4 -4
- package/src/AllowLists/SimpleAllowList.ts +86 -65
- package/src/AllowLists/SimpleDenyList.test.ts +4 -4
- package/src/AllowLists/SimpleDenyList.ts +87 -126
- package/src/Auth/PassthroughAuth.test.ts +1 -1
- package/src/Auth/PassthroughAuth.ts +1 -1
- package/src/Boost.ts +147 -15
- package/src/BoostCore.test.ts +326 -278
- package/src/BoostCore.ts +425 -242
- package/src/BoostRegistry.test.ts +53 -0
- package/src/BoostRegistry.ts +168 -50
- package/src/Budgets/Budget.test.ts +2 -2
- package/src/Budgets/Budget.ts +1 -2
- package/src/Budgets/ManagedBudget.test.ts +82 -19
- package/src/Budgets/ManagedBudget.ts +106 -315
- package/src/Budgets/VestingBudget.test.ts +7 -7
- package/src/Budgets/VestingBudget.ts +110 -112
- package/src/Deployable/Contract.ts +5 -6
- package/src/Deployable/Deployable.ts +1 -1
- package/src/Deployable/DeployableTarget.ts +32 -21
- package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
- package/src/Incentives/AllowListIncentive.test.ts +7 -10
- package/src/Incentives/AllowListIncentive.ts +88 -30
- package/src/Incentives/CGDAIncentive.test.ts +11 -12
- package/src/Incentives/CGDAIncentive.ts +161 -37
- package/src/Incentives/ERC1155Incentive.test.ts +5 -16
- package/src/Incentives/ERC1155Incentive.ts +132 -51
- package/src/Incentives/ERC20Incentive.test.ts +15 -23
- package/src/Incentives/ERC20Incentive.ts +131 -46
- package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +324 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +12 -35
- package/src/Incentives/ERC20VariableIncentive.ts +118 -43
- package/src/Incentives/Incentive.test.ts +5 -2
- package/src/Incentives/Incentive.ts +7 -6
- package/src/Incentives/PointsIncentive.test.ts +26 -30
- package/src/Incentives/PointsIncentive.ts +110 -34
- package/src/Validators/SignerValidator.test.ts +9 -13
- package/src/Validators/SignerValidator.ts +437 -26
- package/src/Validators/Validator.test.ts +2 -2
- package/src/Validators/Validator.ts +1 -1
- package/src/claiming.ts +56 -0
- package/src/errors.ts +346 -22
- package/src/index.test.ts +118 -36
- package/src/index.ts +15 -7
- package/src/transfers.ts +284 -0
- package/src/utils.test.ts +2 -2
- package/src/utils.ts +61 -2061
- package/dist/Budgets/SimpleBudget.d.ts.map +0 -1
- package/dist/componentInterfaces-CKCBwG16.cjs +0 -2
- package/dist/componentInterfaces-CKCBwG16.cjs.map +0 -1
- package/dist/componentInterfaces-DYkaxBda.js +0 -13
- package/dist/componentInterfaces-DYkaxBda.js.map +0 -1
- package/dist/generated-BzszviNp.cjs +0 -3
- package/dist/generated-BzszviNp.cjs.map +0 -1
- package/dist/generated-Cbv8zFkf.js.map +0 -1
- package/src/Budgets/SimpleBudget.test.ts +0 -152
- package/src/Budgets/SimpleBudget.ts +0 -521
|
@@ -7,55 +7,336 @@ import {
|
|
|
7
7
|
} from '@boostxyz/evm';
|
|
8
8
|
import { bytecode } from '@boostxyz/evm/artifacts/contracts/actions/EventAction.sol/EventAction.json';
|
|
9
9
|
import events from '@boostxyz/signatures/events';
|
|
10
|
+
import functions from '@boostxyz/signatures/functions';
|
|
11
|
+
import {
|
|
12
|
+
GetTransactionReceiptParameters,
|
|
13
|
+
getTransaction,
|
|
14
|
+
getTransactionReceipt,
|
|
15
|
+
} from '@wagmi/core';
|
|
16
|
+
import { match } from 'ts-pattern';
|
|
10
17
|
import {
|
|
11
18
|
type Abi,
|
|
12
19
|
type AbiEvent,
|
|
20
|
+
type AbiFunction,
|
|
21
|
+
AbiItem,
|
|
13
22
|
type Address,
|
|
14
23
|
type ContractEventName,
|
|
24
|
+
type ContractFunctionName,
|
|
25
|
+
type GetLogsReturnType,
|
|
26
|
+
type GetTransactionParameters,
|
|
15
27
|
type Hex,
|
|
16
28
|
type Log,
|
|
29
|
+
type PublicClient,
|
|
30
|
+
type Transaction,
|
|
31
|
+
decodeEventLog,
|
|
32
|
+
decodeFunctionData,
|
|
33
|
+
encodeAbiParameters,
|
|
34
|
+
fromHex,
|
|
35
|
+
isAddress,
|
|
17
36
|
isAddressEqual,
|
|
37
|
+
zeroHash,
|
|
18
38
|
} from 'viem';
|
|
19
|
-
import {
|
|
39
|
+
import { EventAction as EventActionBases } from '../../dist/deployments.json';
|
|
20
40
|
import type {
|
|
21
41
|
DeployableOptions,
|
|
22
42
|
GenericDeployableParams,
|
|
23
43
|
} from '../Deployable/Deployable';
|
|
24
44
|
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
25
45
|
import {
|
|
46
|
+
DecodedArgsMalformedError,
|
|
26
47
|
FieldValueNotComparableError,
|
|
27
48
|
FieldValueUndefinedError,
|
|
49
|
+
FunctionDataDecodeError,
|
|
28
50
|
InvalidNumericalCriteriaError,
|
|
29
51
|
NoEventActionStepsProvidedError,
|
|
30
52
|
TooManyEventActionStepsProvidedError,
|
|
53
|
+
UnparseableAbiParamError,
|
|
31
54
|
UnrecognizedFilterTypeError,
|
|
55
|
+
ValidationAbiMissingError,
|
|
32
56
|
} from '../errors';
|
|
33
57
|
import {
|
|
34
|
-
type ActionClaimant,
|
|
35
|
-
type ActionStep,
|
|
36
|
-
type Criteria,
|
|
37
|
-
type EventActionPayload,
|
|
38
|
-
type EventActionPayloadRaw,
|
|
39
|
-
FilterType,
|
|
40
58
|
type GetLogsParams,
|
|
41
|
-
|
|
59
|
+
type Overwrite,
|
|
42
60
|
type ReadParams,
|
|
43
61
|
RegistryType,
|
|
44
62
|
type WriteParams,
|
|
45
|
-
dedupeActionSteps,
|
|
46
|
-
isEventActionPayloadSimple,
|
|
47
|
-
prepareEventActionPayload,
|
|
48
63
|
} from '../utils';
|
|
49
|
-
import type { SignatureType } from './../utils';
|
|
50
64
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
/*
|
|
66
|
+
* Action Event Payloads
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Filter types used to determine how criteria are evaluated.
|
|
71
|
+
*
|
|
72
|
+
* @export
|
|
73
|
+
* @enum {number}
|
|
74
|
+
*/
|
|
75
|
+
export enum FilterType {
|
|
76
|
+
EQUAL = 0,
|
|
77
|
+
NOT_EQUAL = 1,
|
|
78
|
+
GREATER_THAN = 2,
|
|
79
|
+
LESS_THAN = 3,
|
|
80
|
+
CONTAINS = 4,
|
|
81
|
+
REGEX = 5,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The primitive types supported for filtering.
|
|
86
|
+
*
|
|
87
|
+
* @export
|
|
88
|
+
* @enum {number}
|
|
89
|
+
*/
|
|
90
|
+
export enum PrimitiveType {
|
|
91
|
+
UINT = 0,
|
|
92
|
+
ADDRESS = 1,
|
|
93
|
+
BYTES = 2,
|
|
94
|
+
STRING = 3,
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Object representation of a `Criteria` struct used in event actions.
|
|
99
|
+
*
|
|
100
|
+
* @export
|
|
101
|
+
* @interface Criteria
|
|
102
|
+
* @typedef {Criteria}
|
|
103
|
+
*/
|
|
104
|
+
export interface Criteria {
|
|
105
|
+
/**
|
|
106
|
+
* The filter type used in this criteria.
|
|
107
|
+
*
|
|
108
|
+
* @type {FilterType}
|
|
109
|
+
*/
|
|
110
|
+
filterType: FilterType;
|
|
111
|
+
/**
|
|
112
|
+
* The primitive type of the field being filtered.
|
|
113
|
+
*
|
|
114
|
+
* @type {PrimitiveType}
|
|
115
|
+
*/
|
|
116
|
+
fieldType: PrimitiveType;
|
|
117
|
+
/**
|
|
118
|
+
* The index in the logs argument array where the field is located.
|
|
119
|
+
*
|
|
120
|
+
* @type {number}
|
|
121
|
+
*/
|
|
122
|
+
fieldIndex: number;
|
|
123
|
+
/**
|
|
124
|
+
* The filter data used for complex filtering.
|
|
125
|
+
*
|
|
126
|
+
* @type {Hex}
|
|
127
|
+
*/
|
|
128
|
+
filterData: Hex;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Whether a given signature is an event or function
|
|
133
|
+
*
|
|
134
|
+
* @export
|
|
135
|
+
* @enum {number}
|
|
136
|
+
*/
|
|
137
|
+
export enum SignatureType {
|
|
138
|
+
EVENT = 0,
|
|
139
|
+
FUNC = 1,
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The payload describing how claimants are identified
|
|
144
|
+
*
|
|
145
|
+
* @export
|
|
146
|
+
* @interface ActionClaimant
|
|
147
|
+
* @typedef {ActionClaimant}
|
|
148
|
+
*/
|
|
149
|
+
export interface ActionClaimant {
|
|
150
|
+
/**
|
|
151
|
+
* Whether claimaint is inferred from event or function
|
|
152
|
+
*
|
|
153
|
+
* @type {SignatureType}
|
|
154
|
+
*/
|
|
155
|
+
signatureType: SignatureType;
|
|
156
|
+
/**
|
|
157
|
+
* The 4 byte signature of the event or function
|
|
158
|
+
*
|
|
159
|
+
* @type {Hex}
|
|
160
|
+
*/
|
|
161
|
+
signature: Hex;
|
|
162
|
+
/**
|
|
163
|
+
* The index corresponding to claimant.
|
|
164
|
+
*
|
|
165
|
+
* @type {number}
|
|
166
|
+
*/
|
|
167
|
+
fieldIndex: number;
|
|
168
|
+
/**
|
|
169
|
+
* The address of the target contract
|
|
170
|
+
*
|
|
171
|
+
* @type {Address}
|
|
172
|
+
*/
|
|
173
|
+
targetContract: Address;
|
|
174
|
+
/**
|
|
175
|
+
* The chain id of the target contract.
|
|
176
|
+
* @type {number}
|
|
177
|
+
*/
|
|
178
|
+
chainid: number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Object representation of an `ActionStep` struct used in event actions.
|
|
183
|
+
*
|
|
184
|
+
* @export
|
|
185
|
+
* @interface ActionStep
|
|
186
|
+
* @typedef {ActionStep}
|
|
187
|
+
*/
|
|
188
|
+
export interface ActionStep {
|
|
189
|
+
/**
|
|
190
|
+
* The signature of the event.
|
|
191
|
+
*
|
|
192
|
+
* @type {Hex}
|
|
193
|
+
*/
|
|
194
|
+
signature: Hex;
|
|
195
|
+
/**
|
|
196
|
+
* Whether claimaint is inferred from event or function
|
|
197
|
+
*
|
|
198
|
+
* @type {SignatureType}
|
|
199
|
+
*/
|
|
200
|
+
signatureType: SignatureType;
|
|
201
|
+
/**
|
|
202
|
+
* The type of action being performed.
|
|
203
|
+
*
|
|
204
|
+
* @type {number}
|
|
205
|
+
*/
|
|
206
|
+
actionType?: number;
|
|
207
|
+
/**
|
|
208
|
+
* The address of the target contract.
|
|
209
|
+
*
|
|
210
|
+
* @type {Address}
|
|
211
|
+
*/
|
|
212
|
+
targetContract: Address;
|
|
213
|
+
/**
|
|
214
|
+
* The chain id of the target contract.
|
|
215
|
+
* @type {number}
|
|
216
|
+
*/
|
|
217
|
+
chainid: number;
|
|
218
|
+
/**
|
|
219
|
+
* The criteria used for this action step.
|
|
220
|
+
*
|
|
221
|
+
* @type {Criteria}
|
|
222
|
+
*/
|
|
223
|
+
actionParameter: Criteria;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Parameters for validating an action step.
|
|
228
|
+
*
|
|
229
|
+
* @typedef {Object} ValidateActionStepParams
|
|
230
|
+
* @property {Record<Hex, AbiEvent | AbiFunction>} [knownSignatures] - Optional record of known events, keyed by 32 byte selectors.
|
|
231
|
+
* @property {AbiEvent | AbiFunction} [abiItem] - Optional ABI item definition.
|
|
232
|
+
* @property {EventLogs} [logs] - Event logs to validate against. Required if 'hash' is not provided.
|
|
233
|
+
* @property {Hex} [hash] - Transaction hash to validate against. Required if 'logs' is not provided.
|
|
234
|
+
* @property {number} [chainId] - Chain ID for the transaction. Required if 'hash' is provided.
|
|
235
|
+
*/
|
|
236
|
+
export type ValidateActionStepParams = {
|
|
237
|
+
knownSignatures?: Record<Hex, AbiEvent | AbiFunction>;
|
|
238
|
+
abiItem?: AbiEvent | AbiFunction;
|
|
239
|
+
} & ({ logs: EventLogs } | { hash: Hex; chainId: number });
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* You can either supply a simplified version of the payload, or one that explicitly declares action steps.
|
|
243
|
+
*
|
|
244
|
+
* @export
|
|
245
|
+
* @typedef {EventActionPayload}
|
|
246
|
+
*/
|
|
247
|
+
export type EventActionPayload =
|
|
248
|
+
| EventActionPayloadSimple
|
|
249
|
+
| EventActionPayloadRaw;
|
|
250
|
+
|
|
251
|
+
export interface EventActionPayloadSimple {
|
|
252
|
+
/**
|
|
253
|
+
* The payload describing how claimants are identified
|
|
254
|
+
*
|
|
255
|
+
* @type {ActionClaimant}
|
|
256
|
+
*/
|
|
257
|
+
actionClaimant: ActionClaimant;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Up to 4 action steps.
|
|
261
|
+
* If you supply less than 4, then the last step will be reused to satisfy the EventAction.InitPayload
|
|
262
|
+
* Any more than 4 will throw an error.
|
|
263
|
+
*
|
|
264
|
+
* @type {ActionStep[]}
|
|
265
|
+
*/
|
|
266
|
+
actionSteps: ActionStep[];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export type ActionStepTuple = [ActionStep, ActionStep, ActionStep, ActionStep];
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Typeguard to determine if a user is supplying a simple or raw EventActionPayload
|
|
273
|
+
*
|
|
274
|
+
* @param {*} opts
|
|
275
|
+
* @returns {opts is EventActionPayloadSimple}
|
|
276
|
+
*/
|
|
277
|
+
export function isEventActionPayloadSimple(
|
|
278
|
+
opts: EventActionPayload,
|
|
279
|
+
): opts is EventActionPayloadSimple {
|
|
280
|
+
return Array.isArray((opts as EventActionPayloadSimple).actionSteps);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Object representation of an `InitPayload` struct used to initialize event actions.
|
|
285
|
+
*
|
|
286
|
+
* @export
|
|
287
|
+
* @interface EventActionPayloadRaw
|
|
288
|
+
* @typedef {EventActionPayloadRaw}
|
|
289
|
+
*/
|
|
290
|
+
export interface EventActionPayloadRaw {
|
|
291
|
+
/**
|
|
292
|
+
* The payload describing how claimants are identified
|
|
293
|
+
*
|
|
294
|
+
* @type {ActionClaimant}
|
|
295
|
+
*/
|
|
296
|
+
actionClaimant: ActionClaimant;
|
|
297
|
+
/**
|
|
298
|
+
* The first action step.
|
|
299
|
+
*
|
|
300
|
+
* @type {ActionStep}
|
|
301
|
+
*/
|
|
302
|
+
actionStepOne: ActionStep;
|
|
303
|
+
/**
|
|
304
|
+
* The second action step.
|
|
305
|
+
*
|
|
306
|
+
* @type {ActionStep}
|
|
307
|
+
*/
|
|
308
|
+
actionStepTwo: ActionStep;
|
|
309
|
+
/**
|
|
310
|
+
* The third action step.
|
|
311
|
+
*
|
|
312
|
+
* @type {ActionStep}
|
|
313
|
+
*/
|
|
314
|
+
actionStepThree: ActionStep;
|
|
315
|
+
/**
|
|
316
|
+
* The fourth action step.
|
|
317
|
+
*
|
|
318
|
+
* @type {ActionStep}
|
|
319
|
+
*/
|
|
320
|
+
actionStepFour: ActionStep;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Array of event logs to pass into TxParams
|
|
325
|
+
* @export
|
|
326
|
+
* @typedef {EventLogs}
|
|
327
|
+
*/
|
|
328
|
+
export type EventLogs = GetLogsReturnType<AbiEvent, AbiEvent[], true>;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Getter params from the event action contract
|
|
332
|
+
*
|
|
333
|
+
* @export
|
|
334
|
+
* @typedef {ReadEventActionParams}
|
|
335
|
+
* @param {fnName} fnName - The getter function name
|
|
336
|
+
*/
|
|
337
|
+
export type ReadEventActionParams<
|
|
338
|
+
fnName extends ContractFunctionName<typeof eventActionAbi, 'pure' | 'view'>,
|
|
339
|
+
> = ReadParams<typeof eventActionAbi, fnName>;
|
|
59
340
|
|
|
60
341
|
/**
|
|
61
342
|
* A generic event action
|
|
@@ -82,9 +363,11 @@ export class EventAction extends DeployableTarget<
|
|
|
82
363
|
*
|
|
83
364
|
* @public
|
|
84
365
|
* @static
|
|
85
|
-
* @type {Address}
|
|
366
|
+
* @type {Record<number, Address>}
|
|
86
367
|
*/
|
|
87
|
-
public static override
|
|
368
|
+
public static override bases: Record<number, Address> = {
|
|
369
|
+
...(EventActionBases as Record<number, Address>),
|
|
370
|
+
};
|
|
88
371
|
/**
|
|
89
372
|
* @inheritdoc
|
|
90
373
|
*
|
|
@@ -100,12 +383,12 @@ export class EventAction extends DeployableTarget<
|
|
|
100
383
|
* @public
|
|
101
384
|
* @async
|
|
102
385
|
* @param {number} index The index of the action event to retrieve
|
|
103
|
-
* @param {?
|
|
386
|
+
* @param {?ReadEventActionParams<'getActionStep'>} [params]
|
|
104
387
|
* @returns {Promise<ActionStep>}
|
|
105
388
|
*/
|
|
106
389
|
public async getActionStep(
|
|
107
390
|
index: number,
|
|
108
|
-
params?:
|
|
391
|
+
params?: ReadEventActionParams<'getActionStep'>,
|
|
109
392
|
) {
|
|
110
393
|
const steps = await this.getActionSteps(params);
|
|
111
394
|
return steps.at(index);
|
|
@@ -116,19 +399,19 @@ export class EventAction extends DeployableTarget<
|
|
|
116
399
|
*
|
|
117
400
|
* @public
|
|
118
401
|
* @async
|
|
119
|
-
* @param {?
|
|
402
|
+
* @param {?ReadEventActionParams<'getActionSteps'>} [params]
|
|
120
403
|
* @returns {Promise<ActionStep[]>}
|
|
121
404
|
*/
|
|
122
405
|
public async getActionSteps(
|
|
123
|
-
params?:
|
|
406
|
+
params?: ReadEventActionParams<'getActionSteps'>,
|
|
124
407
|
) {
|
|
125
408
|
const steps = (await readEventActionGetActionSteps(this._config, {
|
|
126
409
|
address: this.assertValidAddress(),
|
|
127
410
|
...this.optionallyAttachAccount(),
|
|
128
411
|
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
129
412
|
...(params as any),
|
|
130
|
-
})) as
|
|
131
|
-
return
|
|
413
|
+
})) as RawActionStep[];
|
|
414
|
+
return _dedupeActionSteps(steps.map(_fromRawActionStep));
|
|
132
415
|
}
|
|
133
416
|
|
|
134
417
|
/**
|
|
@@ -136,11 +419,11 @@ export class EventAction extends DeployableTarget<
|
|
|
136
419
|
*
|
|
137
420
|
* @public
|
|
138
421
|
* @async
|
|
139
|
-
* @param {?
|
|
422
|
+
* @param {?ReadEventActionParams<'getActionStepsCount'>} [params]
|
|
140
423
|
* @returns {Promise<bigint>}
|
|
141
424
|
*/
|
|
142
425
|
public async getActionStepsCount(
|
|
143
|
-
params?:
|
|
426
|
+
params?: ReadEventActionParams<'getActionStepsCount'>,
|
|
144
427
|
) {
|
|
145
428
|
const steps = await this.getActionSteps(params);
|
|
146
429
|
return steps.length;
|
|
@@ -151,18 +434,18 @@ export class EventAction extends DeployableTarget<
|
|
|
151
434
|
*
|
|
152
435
|
* @public
|
|
153
436
|
* @async
|
|
154
|
-
* @param {?
|
|
437
|
+
* @param {?ReadEventActionParams<'getActionClaimant'>} [params]
|
|
155
438
|
* @returns {Promise<ActionClaimant>}
|
|
156
439
|
*/
|
|
157
440
|
public async getActionClaimant(
|
|
158
|
-
params?:
|
|
159
|
-
) {
|
|
160
|
-
|
|
441
|
+
params?: ReadEventActionParams<'getActionClaimant'>,
|
|
442
|
+
): Promise<ActionClaimant> {
|
|
443
|
+
const result = (await readEventActionGetActionClaimant(this._config, {
|
|
161
444
|
address: this.assertValidAddress(),
|
|
162
445
|
...this.optionallyAttachAccount(),
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
446
|
+
...params,
|
|
447
|
+
})) as RawActionClaimant;
|
|
448
|
+
return _fromRawActionStep(result);
|
|
166
449
|
}
|
|
167
450
|
|
|
168
451
|
/**
|
|
@@ -171,14 +454,14 @@ export class EventAction extends DeployableTarget<
|
|
|
171
454
|
* @public
|
|
172
455
|
* @async
|
|
173
456
|
* @param {Hex} data
|
|
174
|
-
* @param {?WriteParams
|
|
457
|
+
* @param {?WriteParams} [params]
|
|
175
458
|
* @returns {Promise<readonly [boolean, `0x${string}`]>}
|
|
176
459
|
*/
|
|
177
460
|
public async execute(
|
|
178
461
|
data: Hex,
|
|
179
462
|
params?: WriteParams<typeof eventActionAbi, 'execute'>,
|
|
180
463
|
) {
|
|
181
|
-
return this.awaitResult(this.executeRaw(data, params));
|
|
464
|
+
return await this.awaitResult(this.executeRaw(data, params));
|
|
182
465
|
}
|
|
183
466
|
|
|
184
467
|
/**
|
|
@@ -187,8 +470,8 @@ export class EventAction extends DeployableTarget<
|
|
|
187
470
|
* @public
|
|
188
471
|
* @async
|
|
189
472
|
* @param {Hex} data
|
|
190
|
-
* @param {?WriteParams
|
|
191
|
-
* @returns {
|
|
473
|
+
* @param {?WriteParams} [params]
|
|
474
|
+
* @returns {Promise<{ hash: `0x${string}`; result: readonly [boolean, `0x${string}`]; }>}
|
|
192
475
|
*/
|
|
193
476
|
public async executeRaw(
|
|
194
477
|
data: Hex,
|
|
@@ -205,27 +488,154 @@ export class EventAction extends DeployableTarget<
|
|
|
205
488
|
return { hash, result };
|
|
206
489
|
}
|
|
207
490
|
|
|
491
|
+
/**
|
|
492
|
+
* Derives the action claimant address from a transaction based on the provided ActionClaimant configuration.
|
|
493
|
+
* This method supports both event-based and function-based claimant derivation.
|
|
494
|
+
*
|
|
495
|
+
** @example
|
|
496
|
+
* // Example usage
|
|
497
|
+
* const eventAction = boost.action as EventAction
|
|
498
|
+
* const claimant = await eventAction.getActionClaimant() // {
|
|
499
|
+
* signatureType: SignatureType.EVENT,
|
|
500
|
+
* signature: '0x1234...',
|
|
501
|
+
* fieldIndex: 2,
|
|
502
|
+
* targetContract: '0xabcd...',
|
|
503
|
+
* chainid: 1
|
|
504
|
+
* };
|
|
505
|
+
* const params: ValidateActionStepParams = {
|
|
506
|
+
* hash: '0x5678...',
|
|
507
|
+
* chainId: 1,
|
|
508
|
+
* knownSignatures?: {
|
|
509
|
+
* '0x1234...': {}
|
|
510
|
+
* }
|
|
511
|
+
* };
|
|
512
|
+
* const claimantAddress = await eventAction.deriveActionClaimantFromTransaction(claimant, params);
|
|
513
|
+
*
|
|
514
|
+
* @param {ActionClaimant} claimant - The configuration specifying how to derive the claimant.
|
|
515
|
+
* @param {ValidateActionStepParams} params - Parameters for validation, including transaction hash, known signatures, logs, and chain ID.
|
|
516
|
+
* @returns {Promise<Address | undefined>} The derived claimant address if found, undefined otherwise.
|
|
517
|
+
* @throws {ValidationAbiMissingError} If the ABI for the specified signature is not found.
|
|
518
|
+
* @throws {FunctionDataDecodeError} If there's an error decoding function data (for function-based derivation).
|
|
519
|
+
*/
|
|
520
|
+
public async deriveActionClaimantFromTransaction(
|
|
521
|
+
claimant: ActionClaimant,
|
|
522
|
+
params: ValidateActionStepParams,
|
|
523
|
+
): Promise<Address | undefined> {
|
|
524
|
+
const signature = claimant.signature;
|
|
525
|
+
if (claimant.signatureType === SignatureType.EVENT) {
|
|
526
|
+
let event: AbiEvent;
|
|
527
|
+
if (params.abiItem) event = params.abiItem as AbiEvent;
|
|
528
|
+
else {
|
|
529
|
+
const sigPool: Record<Hex, AbiEvent> = {
|
|
530
|
+
...(events.abi as Record<Hex, AbiEvent>),
|
|
531
|
+
...((params.knownSignatures as Record<Hex, AbiEvent>) || {}),
|
|
532
|
+
};
|
|
533
|
+
event = sigPool[signature] as AbiEvent;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (!event) {
|
|
537
|
+
throw new ValidationAbiMissingError(signature);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
let address: Address | undefined;
|
|
541
|
+
if ('logs' in params) {
|
|
542
|
+
for (let log of params.logs) {
|
|
543
|
+
if (!isAddressEqual(log.address, claimant.targetContract)) continue;
|
|
544
|
+
let addressCandidate = this.validateClaimantAgainstArgs(
|
|
545
|
+
claimant,
|
|
546
|
+
log,
|
|
547
|
+
);
|
|
548
|
+
if (addressCandidate) address = addressCandidate;
|
|
549
|
+
}
|
|
550
|
+
return address;
|
|
551
|
+
}
|
|
552
|
+
const receipt = await getTransactionReceipt(this._config, params);
|
|
553
|
+
const decodedLogs = receipt.logs.map((log) => {
|
|
554
|
+
const { eventName, args } = decodeEventLog({
|
|
555
|
+
abi: [event],
|
|
556
|
+
data: log.data,
|
|
557
|
+
topics: log.topics,
|
|
558
|
+
});
|
|
559
|
+
return { ...log, eventName, args };
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
for (let log of decodedLogs) {
|
|
563
|
+
if (!isAddressEqual(log.address, claimant.targetContract)) continue;
|
|
564
|
+
let addressCandidate = this.validateClaimantAgainstArgs(claimant, log);
|
|
565
|
+
if (addressCandidate) address = addressCandidate;
|
|
566
|
+
}
|
|
567
|
+
return address;
|
|
568
|
+
}
|
|
569
|
+
if (
|
|
570
|
+
claimant.signatureType === SignatureType.FUNC &&
|
|
571
|
+
'hash' in params &&
|
|
572
|
+
'chainId' in params
|
|
573
|
+
) {
|
|
574
|
+
const transaction = await getTransaction(this._config, {
|
|
575
|
+
hash: params.hash,
|
|
576
|
+
});
|
|
577
|
+
if (!isAddressEqual(transaction.to!, claimant.targetContract)) return;
|
|
578
|
+
let func: AbiFunction;
|
|
579
|
+
if (params.abiItem) func = params.abiItem as AbiFunction;
|
|
580
|
+
else {
|
|
581
|
+
const sigPool: Record<Hex, AbiFunction> = {
|
|
582
|
+
...(functions.abi as Record<Hex, AbiFunction>),
|
|
583
|
+
...((params.knownSignatures as Record<Hex, AbiFunction>) || {}),
|
|
584
|
+
};
|
|
585
|
+
func = sigPool[signature] as AbiFunction;
|
|
586
|
+
}
|
|
587
|
+
if (!func) {
|
|
588
|
+
throw new ValidationAbiMissingError(claimant.signature);
|
|
589
|
+
}
|
|
590
|
+
let decodedData;
|
|
591
|
+
try {
|
|
592
|
+
decodedData = decodeFunctionData({
|
|
593
|
+
abi: [func],
|
|
594
|
+
data: transaction.input,
|
|
595
|
+
});
|
|
596
|
+
} catch (e) {
|
|
597
|
+
throw new FunctionDataDecodeError([func], e as Error);
|
|
598
|
+
}
|
|
599
|
+
return this.validateClaimantAgainstArgs(claimant, decodedData);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Validates the action claimant against the arguments of a log or function data.
|
|
605
|
+
*
|
|
606
|
+
* @param {ActionClaimant} claimant - The action claimant to validate.
|
|
607
|
+
* @param {Object} [logOrFnData] - Optional object containing the arguments to validate against.
|
|
608
|
+
* @param {Array<any> | readonly unknown[] | Record<string, unknown>} [logOrFnData.args] - The arguments from the log or function data.
|
|
609
|
+
* @returns {Address | undefined} The validated address if found and valid, otherwise undefined.
|
|
610
|
+
*/
|
|
611
|
+
public validateClaimantAgainstArgs(
|
|
612
|
+
claimant: ActionClaimant,
|
|
613
|
+
logOrFnData?: {
|
|
614
|
+
args: Array<unknown> | readonly unknown[] | Record<string, unknown>;
|
|
615
|
+
},
|
|
616
|
+
): Address | undefined {
|
|
617
|
+
if (
|
|
618
|
+
!logOrFnData ||
|
|
619
|
+
!Array.isArray(logOrFnData?.args) ||
|
|
620
|
+
logOrFnData?.args.length <= claimant.fieldIndex
|
|
621
|
+
) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
const maybeAddress = logOrFnData.args.at(claimant.fieldIndex);
|
|
625
|
+
if (isAddress(maybeAddress)) return maybeAddress;
|
|
626
|
+
}
|
|
627
|
+
|
|
208
628
|
/**
|
|
209
629
|
* Retrieves action steps, and uses them to validate against, and optionally fetch logs that match the step's signature.
|
|
210
630
|
* If logs are provided in the optional `params` argument, then those logs will be used instead of fetched with the configured client.
|
|
211
631
|
*
|
|
212
632
|
* @public
|
|
213
633
|
* @async
|
|
214
|
-
* @param
|
|
215
|
-
* GetLogsParams<Abi, ContractEventName<Abi>> & {
|
|
216
|
-
* knownEvents?: Record<Hex, AbiEvent>;
|
|
217
|
-
* logs?: Log[];
|
|
218
|
-
* }} [params]
|
|
634
|
+
* @param ValidateActionStepParams params
|
|
219
635
|
* @returns {Promise<boolean>}
|
|
220
636
|
*/
|
|
221
|
-
public async validateActionSteps(
|
|
222
|
-
|
|
223
|
-
GetLogsParams<Abi, ContractEventName<Abi>> & {
|
|
224
|
-
knownEvents?: Record<Hex, AbiEvent>;
|
|
225
|
-
logs?: Log[];
|
|
226
|
-
},
|
|
227
|
-
) {
|
|
228
|
-
const actionSteps = await this.getActionSteps(params);
|
|
637
|
+
public async validateActionSteps(params: ValidateActionStepParams) {
|
|
638
|
+
const actionSteps = await this.getActionSteps();
|
|
229
639
|
for (const actionStep of actionSteps) {
|
|
230
640
|
if (!(await this.isActionStepValid(actionStep, params))) {
|
|
231
641
|
return false;
|
|
@@ -235,106 +645,339 @@ export class EventAction extends DeployableTarget<
|
|
|
235
645
|
}
|
|
236
646
|
|
|
237
647
|
/**
|
|
238
|
-
* Validates a single action step with a given criteria against logs.
|
|
239
|
-
* If logs are provided in the optional `params` argument, then those logs will be used instead of fetched with the configured client.
|
|
648
|
+
* Validates a single action step with a given criteria against logs or function calls.
|
|
649
|
+
* If logs are provided in the optional `params` argument, then those logs will be used instead of being fetched with the configured client.
|
|
650
|
+
* For functions a hash is required.
|
|
240
651
|
*
|
|
241
652
|
* @public
|
|
242
653
|
* @async
|
|
243
|
-
* @param {ActionStep} actionStep
|
|
244
|
-
* @param {
|
|
245
|
-
* knownEvents?: Record<Hex, AbiEvent>;
|
|
246
|
-
* logs?: Log[];
|
|
247
|
-
* }} [params]
|
|
654
|
+
* @param {ActionStep} actionStep - The action step to validate. Can be a function of event step.
|
|
655
|
+
* @param {ValidateActionStepParams} params - Additional parameters for validation, including hash, known events, logs, and chain ID.
|
|
248
656
|
* @returns {Promise<boolean>}
|
|
249
657
|
*/
|
|
250
658
|
public async isActionStepValid(
|
|
251
659
|
actionStep: ActionStep,
|
|
252
|
-
params
|
|
253
|
-
knownEvents?: Record<Hex, AbiEvent>;
|
|
254
|
-
logs?: Log[];
|
|
255
|
-
},
|
|
660
|
+
params: ValidateActionStepParams,
|
|
256
661
|
) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
662
|
+
if (actionStep.signatureType === SignatureType.EVENT) {
|
|
663
|
+
const signature = actionStep.signature;
|
|
664
|
+
let event: AbiEvent;
|
|
665
|
+
if (params.abiItem) event = params.abiItem as AbiEvent;
|
|
666
|
+
else {
|
|
667
|
+
const sigPool: Record<Hex, AbiEvent> = {
|
|
668
|
+
...(events.abi as Record<Hex, AbiEvent>),
|
|
669
|
+
...((params.knownSignatures as Record<Hex, AbiEvent>) || {}),
|
|
670
|
+
};
|
|
671
|
+
event = sigPool[signature] as AbiEvent;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (!event) {
|
|
675
|
+
throw new ValidationAbiMissingError(signature);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
if (this.isArraylikeIndexed(actionStep, event)) {
|
|
679
|
+
// If the field is indexed, we can't filter on it
|
|
680
|
+
throw new UnparseableAbiParamError(
|
|
681
|
+
actionStep.actionParameter.fieldIndex,
|
|
682
|
+
event,
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// Use the provided logs, no need to fetch receipt
|
|
687
|
+
if ('logs' in params) {
|
|
688
|
+
return this.isActionEventValid(actionStep, params.logs);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const client = this._config.getClient({
|
|
692
|
+
chainId: params.chainId,
|
|
693
|
+
}) as PublicClient;
|
|
694
|
+
const receipt = await client.getTransactionReceipt({
|
|
695
|
+
hash: params.hash,
|
|
696
|
+
});
|
|
697
|
+
const decodedLogs = receipt.logs.map((log) => {
|
|
698
|
+
const { eventName, args } = decodeEventLog({
|
|
699
|
+
abi: [event],
|
|
700
|
+
data: log.data,
|
|
701
|
+
topics: log.topics,
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
return { ...log, eventName, args };
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
return this.isActionEventValid(actionStep, decodedLogs);
|
|
265
708
|
}
|
|
266
|
-
if (
|
|
267
|
-
|
|
709
|
+
if (actionStep.signatureType === SignatureType.FUNC) {
|
|
710
|
+
if ('hash' in params && 'chainId' in params) {
|
|
711
|
+
const client = this._config.getClient({
|
|
712
|
+
chainId: params.chainId,
|
|
713
|
+
}) as PublicClient;
|
|
714
|
+
const transaction = await client.getTransaction({
|
|
715
|
+
hash: params.hash,
|
|
716
|
+
});
|
|
717
|
+
return this.isActionFunctionValid(actionStep, transaction, params);
|
|
718
|
+
}
|
|
268
719
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
720
|
+
return false;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Validates a single action event with a given criteria against logs.
|
|
725
|
+
* If logs are provided in the optional `params` argument, then those logs will be used instead of being fetched with the configured client.
|
|
726
|
+
*
|
|
727
|
+
* @public
|
|
728
|
+
* @async
|
|
729
|
+
* @param {ActionStep} actionStep - The action step containing the event to validate.
|
|
730
|
+
* @param {EventLogs} logs - Event logs to validate the given step against
|
|
731
|
+
* @returns {Promise<boolean>} Resolves to true if the action event is valid, throws if input is invalid, otherwise false.
|
|
732
|
+
*/
|
|
733
|
+
public isActionEventValid(actionStep: ActionStep, logs: EventLogs) {
|
|
734
|
+
const criteria = actionStep.actionParameter;
|
|
279
735
|
if (!logs.length) return false;
|
|
280
736
|
for (let log of logs) {
|
|
281
|
-
if (
|
|
282
|
-
return
|
|
737
|
+
if (this.validateLogAgainstCriteria(criteria, log)) {
|
|
738
|
+
return true;
|
|
283
739
|
}
|
|
284
740
|
}
|
|
285
|
-
return
|
|
741
|
+
return false;
|
|
286
742
|
}
|
|
287
743
|
|
|
288
744
|
/**
|
|
289
|
-
* Validates a
|
|
745
|
+
* Validates a single action function with a given criteria against the transaction input.
|
|
746
|
+
*
|
|
747
|
+
* @public
|
|
748
|
+
* @param {ActionStep} actionStep - The action step containing the function to validate.
|
|
749
|
+
* @param {Transaction} transaction - The transaction that will be validated against.
|
|
750
|
+
* @param {Object} [params] - Optional parameters for validation.
|
|
751
|
+
* @param {AbiItem} [params.abiItem] - The ABI item for the function, if known.
|
|
752
|
+
* @param {Record<Hex, AbiEvent | AbiFunction>} [params.knownSignatures] - A record of known signatures.
|
|
753
|
+
* @returns {boolean} Returns true if the action function is valid, false otherwise.
|
|
754
|
+
* @throws {ValidationAbiMissingError} Throws if the ABI for the function signature is not found.
|
|
755
|
+
* @throws {FunctionDataDecodeError} Throws if there's an error decoding the function data.
|
|
756
|
+
*/
|
|
757
|
+
public isActionFunctionValid(
|
|
758
|
+
actionStep: ActionStep,
|
|
759
|
+
transaction: Transaction,
|
|
760
|
+
params?: Pick<ValidateActionStepParams, 'abiItem' | 'knownSignatures'>,
|
|
761
|
+
) {
|
|
762
|
+
const criteria = actionStep.actionParameter;
|
|
763
|
+
let signature = actionStep.signature;
|
|
764
|
+
|
|
765
|
+
let func: AbiFunction;
|
|
766
|
+
if (params?.abiItem) func = params?.abiItem as AbiFunction;
|
|
767
|
+
else {
|
|
768
|
+
const sigPool: Record<Hex, AbiFunction> = {
|
|
769
|
+
...(functions.abi as Record<Hex, AbiFunction>),
|
|
770
|
+
...((params?.knownSignatures as Record<Hex, AbiFunction>) || {}),
|
|
771
|
+
};
|
|
772
|
+
func = sigPool[signature] as AbiFunction;
|
|
773
|
+
}
|
|
774
|
+
if (!func) {
|
|
775
|
+
throw new ValidationAbiMissingError(signature);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
let decodedData;
|
|
779
|
+
try {
|
|
780
|
+
decodedData = decodeFunctionData({
|
|
781
|
+
abi: [func],
|
|
782
|
+
data: transaction.input,
|
|
783
|
+
});
|
|
784
|
+
} catch (e) {
|
|
785
|
+
throw new FunctionDataDecodeError([func], e as Error);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
// Validate the criteria against decoded arguments using fieldIndex
|
|
789
|
+
const decodedArgs = decodedData.args;
|
|
790
|
+
|
|
791
|
+
if (!decodedArgs || !decodedData) return false;
|
|
792
|
+
|
|
793
|
+
if (
|
|
794
|
+
!this.validateFunctionAgainstCriteria(
|
|
795
|
+
criteria,
|
|
796
|
+
decodedArgs as (string | bigint)[],
|
|
797
|
+
)
|
|
798
|
+
) {
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Validates a field against a given criteria.
|
|
290
806
|
*
|
|
291
807
|
* @param {Criteria} criteria - The criteria to validate against.
|
|
292
|
-
* @param {
|
|
293
|
-
* @
|
|
808
|
+
* @param {string | bigint | Hex} fieldValue - The field value to validate.
|
|
809
|
+
* @param {Object} input - Additional context for validation.
|
|
810
|
+
* @param {EventLogs[0]} [input.log] - The event log, if validating an event.
|
|
811
|
+
* @param {readonly (string | bigint)[]} [input.decodedArgs] - The decoded function arguments, if validating a function call.
|
|
812
|
+
* @returns {Promise<boolean>} - Returns true if the field passes the criteria, false otherwise.
|
|
294
813
|
*/
|
|
295
|
-
public
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
814
|
+
public validateFieldAgainstCriteria(
|
|
815
|
+
criteria: Criteria,
|
|
816
|
+
fieldValue: string | bigint | Hex,
|
|
817
|
+
input:
|
|
818
|
+
| { log: EventLogs[0] }
|
|
819
|
+
| { decodedArgs: readonly (string | bigint)[] },
|
|
820
|
+
): boolean {
|
|
821
|
+
if (
|
|
822
|
+
criteria.filterType === FilterType.EQUAL &&
|
|
823
|
+
criteria.fieldType === PrimitiveType.BYTES &&
|
|
824
|
+
criteria.fieldIndex === 255
|
|
825
|
+
) {
|
|
826
|
+
return true;
|
|
299
827
|
}
|
|
828
|
+
|
|
300
829
|
// Type narrow based on criteria.filterType
|
|
301
830
|
switch (criteria.filterType) {
|
|
302
831
|
case FilterType.EQUAL:
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
criteria.filterData,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
832
|
+
return match(criteria.fieldType)
|
|
833
|
+
.with(PrimitiveType.ADDRESS, () =>
|
|
834
|
+
isAddressEqual(criteria.filterData, fieldValue as Address),
|
|
835
|
+
)
|
|
836
|
+
.with(
|
|
837
|
+
PrimitiveType.UINT,
|
|
838
|
+
() => BigInt(fieldValue) === BigInt(criteria.filterData),
|
|
839
|
+
)
|
|
840
|
+
.with(
|
|
841
|
+
PrimitiveType.STRING,
|
|
842
|
+
() => fieldValue === fromHex(criteria.filterData, 'string'),
|
|
843
|
+
)
|
|
844
|
+
.otherwise(() => fieldValue === criteria.filterData);
|
|
310
845
|
|
|
311
846
|
case FilterType.NOT_EQUAL:
|
|
312
|
-
return
|
|
847
|
+
return match(criteria.fieldType)
|
|
848
|
+
.with(
|
|
849
|
+
PrimitiveType.ADDRESS,
|
|
850
|
+
() => !isAddressEqual(criteria.filterData, fieldValue as Address),
|
|
851
|
+
)
|
|
852
|
+
.with(
|
|
853
|
+
PrimitiveType.UINT,
|
|
854
|
+
() => BigInt(fieldValue) !== BigInt(criteria.filterData),
|
|
855
|
+
)
|
|
856
|
+
.with(
|
|
857
|
+
PrimitiveType.STRING,
|
|
858
|
+
() => fieldValue !== fromHex(criteria.filterData, 'string'),
|
|
859
|
+
)
|
|
860
|
+
.otherwise(() => fieldValue !== criteria.filterData);
|
|
313
861
|
|
|
314
862
|
case FilterType.GREATER_THAN:
|
|
315
863
|
if (criteria.fieldType === PrimitiveType.UINT) {
|
|
316
864
|
return BigInt(fieldValue) > BigInt(criteria.filterData);
|
|
317
865
|
}
|
|
318
|
-
throw new InvalidNumericalCriteriaError({
|
|
866
|
+
throw new InvalidNumericalCriteriaError({
|
|
867
|
+
...input,
|
|
868
|
+
criteria,
|
|
869
|
+
fieldValue,
|
|
870
|
+
});
|
|
319
871
|
|
|
320
872
|
case FilterType.LESS_THAN:
|
|
321
873
|
if (criteria.fieldType === PrimitiveType.UINT) {
|
|
322
874
|
return BigInt(fieldValue) < BigInt(criteria.filterData);
|
|
323
875
|
}
|
|
324
|
-
throw new InvalidNumericalCriteriaError({
|
|
876
|
+
throw new InvalidNumericalCriteriaError({
|
|
877
|
+
...input,
|
|
878
|
+
criteria,
|
|
879
|
+
fieldValue,
|
|
880
|
+
});
|
|
325
881
|
|
|
326
882
|
case FilterType.CONTAINS:
|
|
327
883
|
if (
|
|
328
884
|
criteria.fieldType === PrimitiveType.BYTES ||
|
|
329
885
|
criteria.fieldType === PrimitiveType.STRING
|
|
330
886
|
) {
|
|
331
|
-
|
|
887
|
+
let substring;
|
|
888
|
+
if (criteria.fieldType === PrimitiveType.STRING) {
|
|
889
|
+
substring = fromHex(criteria.filterData, 'string');
|
|
890
|
+
} else {
|
|
891
|
+
// truncate the `0x` prefix
|
|
892
|
+
substring = criteria.filterData.slice(2);
|
|
893
|
+
}
|
|
894
|
+
return (fieldValue as string).includes(substring);
|
|
895
|
+
}
|
|
896
|
+
throw new FieldValueNotComparableError({
|
|
897
|
+
...input,
|
|
898
|
+
criteria,
|
|
899
|
+
fieldValue,
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
case FilterType.REGEX:
|
|
903
|
+
if (typeof fieldValue !== 'string') {
|
|
904
|
+
throw new FieldValueNotComparableError({
|
|
905
|
+
...input,
|
|
906
|
+
criteria,
|
|
907
|
+
fieldValue,
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
if (criteria.fieldType === PrimitiveType.STRING) {
|
|
912
|
+
// fieldValue is decoded by the ABI
|
|
913
|
+
const regexString = fromHex(criteria.filterData, 'string');
|
|
914
|
+
return new RegExp(regexString).test(fieldValue);
|
|
332
915
|
}
|
|
333
|
-
throw new FieldValueNotComparableError({ log, criteria, fieldValue });
|
|
334
916
|
|
|
335
917
|
default:
|
|
336
|
-
throw new UnrecognizedFilterTypeError({
|
|
918
|
+
throw new UnrecognizedFilterTypeError({
|
|
919
|
+
...input,
|
|
920
|
+
criteria,
|
|
921
|
+
fieldValue,
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Validates a {@link Log} against a given criteria.
|
|
928
|
+
* If the criteria's fieldIndex is 255, it is reserved for anyValidation
|
|
929
|
+
*
|
|
930
|
+
* @param {Criteria} criteria - The criteria to validate against.
|
|
931
|
+
* @param {Log} log - The Viem event log.
|
|
932
|
+
* @returns {boolean} - Returns true if the log passes the criteria, false otherwise.
|
|
933
|
+
*/
|
|
934
|
+
public validateLogAgainstCriteria(
|
|
935
|
+
criteria: Criteria,
|
|
936
|
+
log: EventLogs[0],
|
|
937
|
+
): boolean {
|
|
938
|
+
if (
|
|
939
|
+
!Array.isArray(log.args) ||
|
|
940
|
+
(log.args.length <= criteria.fieldIndex && criteria.fieldIndex !== 255)
|
|
941
|
+
) {
|
|
942
|
+
throw new DecodedArgsMalformedError({
|
|
943
|
+
log,
|
|
944
|
+
criteria,
|
|
945
|
+
fieldValue: undefined,
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
const fieldValue =
|
|
950
|
+
criteria.fieldIndex === 255 ? zeroHash : log.args.at(criteria.fieldIndex);
|
|
951
|
+
|
|
952
|
+
if (fieldValue === undefined) {
|
|
953
|
+
throw new FieldValueUndefinedError({ log, criteria, fieldValue });
|
|
954
|
+
}
|
|
955
|
+
return this.validateFieldAgainstCriteria(criteria, fieldValue, { log });
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Validates a function's decoded arguments against a given criteria.
|
|
960
|
+
* If the criteria's fieldIndex is 255, it is reserved for anyValidation
|
|
961
|
+
*
|
|
962
|
+
* @param {Criteria} criteria - The criteria to validate against.
|
|
963
|
+
* @param {unknown[]} decodedArgs - The decoded arguments of the function call.
|
|
964
|
+
* @returns {Promise<boolean>} - Returns true if the decoded argument passes the criteria, false otherwise.
|
|
965
|
+
*/
|
|
966
|
+
public validateFunctionAgainstCriteria(
|
|
967
|
+
criteria: Criteria,
|
|
968
|
+
decodedArgs: readonly (string | bigint)[],
|
|
969
|
+
): boolean {
|
|
970
|
+
const fieldValue =
|
|
971
|
+
criteria.fieldIndex === 255 ? zeroHash : decodedArgs[criteria.fieldIndex];
|
|
972
|
+
if (fieldValue === undefined) {
|
|
973
|
+
throw new FieldValueUndefinedError({
|
|
974
|
+
criteria,
|
|
975
|
+
fieldValue,
|
|
976
|
+
});
|
|
337
977
|
}
|
|
978
|
+
return this.validateFieldAgainstCriteria(criteria, fieldValue, {
|
|
979
|
+
decodedArgs,
|
|
980
|
+
});
|
|
338
981
|
}
|
|
339
982
|
|
|
340
983
|
/**
|
|
@@ -356,24 +999,24 @@ export class EventAction extends DeployableTarget<
|
|
|
356
999
|
let rawPayload: EventActionPayloadRaw;
|
|
357
1000
|
if (isEventActionPayloadSimple(payload)) {
|
|
358
1001
|
// filter out any falsy potential values
|
|
359
|
-
let tmpSteps = payload.actionSteps.filter((step) => !!step);
|
|
1002
|
+
let tmpSteps: ActionStep[] = payload.actionSteps.filter((step) => !!step);
|
|
360
1003
|
if (tmpSteps.length === 0) {
|
|
361
1004
|
throw new NoEventActionStepsProvidedError();
|
|
362
1005
|
}
|
|
363
1006
|
if (tmpSteps.length > 4) {
|
|
364
1007
|
throw new TooManyEventActionStepsProvidedError();
|
|
365
1008
|
}
|
|
366
|
-
let steps:
|
|
1009
|
+
let steps: ActionStepTuple = Array.from({ length: 4 }, (_, i) => {
|
|
367
1010
|
// use either the provided step at the given index, or reuse the previous step
|
|
368
1011
|
// should aways exist
|
|
369
|
-
return tmpSteps.at(i)
|
|
370
|
-
});
|
|
1012
|
+
return tmpSteps.at(i) || tmpSteps.at(-1);
|
|
1013
|
+
}) as ActionStepTuple;
|
|
371
1014
|
rawPayload = {
|
|
372
1015
|
actionClaimant: payload.actionClaimant,
|
|
373
|
-
actionStepOne: steps
|
|
374
|
-
actionStepTwo: steps
|
|
375
|
-
actionStepThree: steps
|
|
376
|
-
actionStepFour: steps
|
|
1016
|
+
actionStepOne: steps[0],
|
|
1017
|
+
actionStepTwo: steps[1],
|
|
1018
|
+
actionStepThree: steps[2],
|
|
1019
|
+
actionStepFour: steps[3],
|
|
377
1020
|
};
|
|
378
1021
|
} else {
|
|
379
1022
|
rawPayload = payload;
|
|
@@ -385,4 +1028,236 @@ export class EventAction extends DeployableTarget<
|
|
|
385
1028
|
...this.optionallyAttachAccount(options.account),
|
|
386
1029
|
};
|
|
387
1030
|
}
|
|
1031
|
+
|
|
1032
|
+
public isArraylikeIndexed(step: ActionStep, event: AbiEvent) {
|
|
1033
|
+
if (
|
|
1034
|
+
(step.actionParameter.fieldType === PrimitiveType.STRING ||
|
|
1035
|
+
step.actionParameter.fieldType === PrimitiveType.BYTES) &&
|
|
1036
|
+
event.inputs[step.actionParameter.fieldIndex]?.indexed
|
|
1037
|
+
) {
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1040
|
+
return false;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function _dedupeActionSteps(_steps: ActionStep[]): ActionStep[] {
|
|
1045
|
+
const steps: ActionStep[] = [],
|
|
1046
|
+
signatures: Record<string, boolean> = {};
|
|
1047
|
+
for (let step of _steps) {
|
|
1048
|
+
const signature = JSON.stringify(step);
|
|
1049
|
+
if (signatures[signature]) continue;
|
|
1050
|
+
steps.push(step);
|
|
1051
|
+
signatures[signature] = true;
|
|
1052
|
+
}
|
|
1053
|
+
return steps;
|
|
1054
|
+
}
|
|
1055
|
+
type RawActionStep = Overwrite<ActionStep, { chainid: bigint }>;
|
|
1056
|
+
type RawActionClaimant = Overwrite<ActionClaimant, { chainid: bigint }>;
|
|
1057
|
+
|
|
1058
|
+
function _toRawActionStep<T extends ActionStep | ActionClaimant>(obj: T) {
|
|
1059
|
+
return {
|
|
1060
|
+
...obj,
|
|
1061
|
+
chainid: BigInt(obj.chainid),
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
function _fromRawActionStep<T extends RawActionStep | RawActionClaimant>(
|
|
1066
|
+
obj: T,
|
|
1067
|
+
) {
|
|
1068
|
+
if (obj.chainid > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
1069
|
+
throw new Error('Chain ID exceeds max safe integer');
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
return {
|
|
1073
|
+
...obj,
|
|
1074
|
+
chainid: Number(obj.chainid),
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/**
|
|
1079
|
+
* Typeguard to determine if a user is supplying a simple or raw EventActionPayload
|
|
1080
|
+
*
|
|
1081
|
+
* @param {*} opts
|
|
1082
|
+
* @returns {opts is EventActionPayloadSimple}
|
|
1083
|
+
*/
|
|
1084
|
+
function _isEventActionPayloadSimple(
|
|
1085
|
+
opts: EventActionPayload,
|
|
1086
|
+
): opts is EventActionPayloadSimple {
|
|
1087
|
+
return Array.isArray((opts as EventActionPayloadSimple).actionSteps);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Function to properly encode an event action payload.
|
|
1092
|
+
*
|
|
1093
|
+
* @param {InitPayload} param0
|
|
1094
|
+
* @param {ActionStep} param0.actionStepOne - The first action step to initialize.
|
|
1095
|
+
* @param {ActionStep} param0.actionStepTwo - The second action step to initialize.
|
|
1096
|
+
* @param {ActionStep} param0.actionStepThree - The third action step to initialize.
|
|
1097
|
+
* @param {ActionStep} param0.actionStepFour - The fourth action step to initialize.
|
|
1098
|
+
* @returns {Hex}
|
|
1099
|
+
*/
|
|
1100
|
+
export function prepareEventActionPayload({
|
|
1101
|
+
actionClaimant,
|
|
1102
|
+
actionStepOne,
|
|
1103
|
+
actionStepTwo,
|
|
1104
|
+
actionStepThree,
|
|
1105
|
+
actionStepFour,
|
|
1106
|
+
}: EventActionPayloadRaw) {
|
|
1107
|
+
// note chainIds are technically uint256 but viem treats them (safely) as numbers,
|
|
1108
|
+
// so we encode them as uint32 here to avoid downcast issues
|
|
1109
|
+
return encodeAbiParameters(
|
|
1110
|
+
[
|
|
1111
|
+
{
|
|
1112
|
+
type: 'tuple',
|
|
1113
|
+
name: 'initPayload',
|
|
1114
|
+
components: [
|
|
1115
|
+
{
|
|
1116
|
+
type: 'tuple',
|
|
1117
|
+
name: 'actionClaimant',
|
|
1118
|
+
components: [
|
|
1119
|
+
{ type: 'uint8', name: 'signatureType' },
|
|
1120
|
+
{ type: 'bytes32', name: 'signature' },
|
|
1121
|
+
{ type: 'uint8', name: 'fieldIndex' },
|
|
1122
|
+
{ type: 'address', name: 'targetContract' },
|
|
1123
|
+
{ type: 'uint256', name: 'chainid' },
|
|
1124
|
+
],
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
type: 'tuple',
|
|
1128
|
+
name: 'actionStepOne',
|
|
1129
|
+
components: [
|
|
1130
|
+
{ type: 'bytes32', name: 'signature' },
|
|
1131
|
+
{ type: 'uint8', name: 'signatureType' },
|
|
1132
|
+
{ type: 'uint8', name: 'actionType' },
|
|
1133
|
+
{ type: 'address', name: 'targetContract' },
|
|
1134
|
+
{ type: 'uint256', name: 'chainid' },
|
|
1135
|
+
{
|
|
1136
|
+
type: 'tuple',
|
|
1137
|
+
name: 'actionParameter',
|
|
1138
|
+
components: [
|
|
1139
|
+
{ type: 'uint8', name: 'filterType' },
|
|
1140
|
+
{ type: 'uint8', name: 'fieldType' },
|
|
1141
|
+
{ type: 'uint8', name: 'fieldIndex' },
|
|
1142
|
+
{ type: 'bytes', name: 'filterData' },
|
|
1143
|
+
],
|
|
1144
|
+
},
|
|
1145
|
+
],
|
|
1146
|
+
},
|
|
1147
|
+
{
|
|
1148
|
+
type: 'tuple',
|
|
1149
|
+
name: 'actionStepTwo',
|
|
1150
|
+
components: [
|
|
1151
|
+
{ type: 'bytes32', name: 'signature' },
|
|
1152
|
+
{ type: 'uint8', name: 'signatureType' },
|
|
1153
|
+
{ type: 'uint8', name: 'actionType' },
|
|
1154
|
+
{ type: 'address', name: 'targetContract' },
|
|
1155
|
+
{ type: 'uint256', name: 'chainid' },
|
|
1156
|
+
{
|
|
1157
|
+
type: 'tuple',
|
|
1158
|
+
name: 'actionParameter',
|
|
1159
|
+
components: [
|
|
1160
|
+
{ type: 'uint8', name: 'filterType' },
|
|
1161
|
+
{ type: 'uint8', name: 'fieldType' },
|
|
1162
|
+
{ type: 'uint8', name: 'fieldIndex' },
|
|
1163
|
+
{ type: 'bytes', name: 'filterData' },
|
|
1164
|
+
],
|
|
1165
|
+
},
|
|
1166
|
+
],
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
type: 'tuple',
|
|
1170
|
+
name: 'actionStepThree',
|
|
1171
|
+
components: [
|
|
1172
|
+
{ type: 'bytes32', name: 'signature' },
|
|
1173
|
+
{ type: 'uint8', name: 'signatureType' },
|
|
1174
|
+
{ type: 'uint8', name: 'actionType' },
|
|
1175
|
+
{ type: 'address', name: 'targetContract' },
|
|
1176
|
+
{ type: 'uint256', name: 'chainid' },
|
|
1177
|
+
{
|
|
1178
|
+
type: 'tuple',
|
|
1179
|
+
name: 'actionParameter',
|
|
1180
|
+
components: [
|
|
1181
|
+
{ type: 'uint8', name: 'filterType' },
|
|
1182
|
+
{ type: 'uint8', name: 'fieldType' },
|
|
1183
|
+
{ type: 'uint8', name: 'fieldIndex' },
|
|
1184
|
+
{ type: 'bytes', name: 'filterData' },
|
|
1185
|
+
],
|
|
1186
|
+
},
|
|
1187
|
+
],
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
type: 'tuple',
|
|
1191
|
+
name: 'actionStepFour',
|
|
1192
|
+
components: [
|
|
1193
|
+
{ type: 'bytes32', name: 'signature' },
|
|
1194
|
+
{ type: 'uint8', name: 'signatureType' },
|
|
1195
|
+
{ type: 'uint8', name: 'actionType' },
|
|
1196
|
+
{ type: 'address', name: 'targetContract' },
|
|
1197
|
+
{ type: 'uint256', name: 'chainid' },
|
|
1198
|
+
{
|
|
1199
|
+
type: 'tuple',
|
|
1200
|
+
name: 'actionParameter',
|
|
1201
|
+
components: [
|
|
1202
|
+
{ type: 'uint8', name: 'filterType' },
|
|
1203
|
+
{ type: 'uint8', name: 'fieldType' },
|
|
1204
|
+
{ type: 'uint8', name: 'fieldIndex' },
|
|
1205
|
+
{ type: 'bytes', name: 'filterData' },
|
|
1206
|
+
],
|
|
1207
|
+
},
|
|
1208
|
+
],
|
|
1209
|
+
},
|
|
1210
|
+
],
|
|
1211
|
+
},
|
|
1212
|
+
],
|
|
1213
|
+
[
|
|
1214
|
+
{
|
|
1215
|
+
actionClaimant: _toRawActionStep(actionClaimant),
|
|
1216
|
+
actionStepOne: {
|
|
1217
|
+
..._toRawActionStep(actionStepOne),
|
|
1218
|
+
actionType: actionStepOne.actionType || 0,
|
|
1219
|
+
},
|
|
1220
|
+
actionStepTwo: {
|
|
1221
|
+
..._toRawActionStep(actionStepTwo),
|
|
1222
|
+
actionType: actionStepTwo.actionType || 0,
|
|
1223
|
+
},
|
|
1224
|
+
actionStepThree: {
|
|
1225
|
+
..._toRawActionStep(actionStepThree),
|
|
1226
|
+
actionType: actionStepThree.actionType || 0,
|
|
1227
|
+
},
|
|
1228
|
+
actionStepFour: {
|
|
1229
|
+
..._toRawActionStep(actionStepFour),
|
|
1230
|
+
actionType: actionStepFour.actionType || 0,
|
|
1231
|
+
},
|
|
1232
|
+
},
|
|
1233
|
+
],
|
|
1234
|
+
);
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* Creates a default Criteria object that allows validation to pass. This is used if you don't care about targeting specific parameters in the action step.
|
|
1239
|
+
*
|
|
1240
|
+
* This function returns a Criteria object with the following properties:
|
|
1241
|
+
* - filterType: Set to EQUAL for exact matching
|
|
1242
|
+
* - fieldType: Set to BYTES to handle any data type
|
|
1243
|
+
* - fieldIndex: Set to 255, which is typically used to indicate "any" or "all" in this context
|
|
1244
|
+
* - filterData: Set to zeroHash (0x0000...0000)
|
|
1245
|
+
*
|
|
1246
|
+
* @returns {Criteria} A Criteria object that can be used to match any action parameter
|
|
1247
|
+
*
|
|
1248
|
+
* @example
|
|
1249
|
+
* const anyCriteria = anyActionParameter();
|
|
1250
|
+
* // Use this criteria in an ActionStep to match any parameter
|
|
1251
|
+
* const actionStep = {
|
|
1252
|
+
* // ... other properties ...
|
|
1253
|
+
* actionParameter: anyCriteria
|
|
1254
|
+
* };
|
|
1255
|
+
*/
|
|
1256
|
+
export function anyActionParameter(): Criteria {
|
|
1257
|
+
return {
|
|
1258
|
+
filterType: FilterType.EQUAL,
|
|
1259
|
+
fieldType: PrimitiveType.BYTES,
|
|
1260
|
+
fieldIndex: 255,
|
|
1261
|
+
filterData: zeroHash,
|
|
1262
|
+
};
|
|
388
1263
|
}
|