@boostxyz/sdk 0.0.0-alpha.9 → 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 +11 -11
- package/dist/Actions/ContractAction.d.ts.map +1 -1
- package/dist/Actions/ERC721MintAction.d.ts +14 -14
- 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 +171 -41
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +15 -392
- 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 +92 -37
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleAllowList.js +55 -71
- 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 +203 -11
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleDenyList.js +11 -112
- package/dist/AllowLists/SimpleDenyList.js.map +1 -1
- package/dist/Auth/PassthroughAuth.cjs +1 -1
- package/dist/Auth/PassthroughAuth.js +1 -1
- package/dist/Boost.cjs +1 -1
- package/dist/Boost.cjs.map +1 -1
- package/dist/Boost.d.ts +20 -21
- package/dist/Boost.d.ts.map +1 -1
- package/dist/Boost.js +43 -57
- 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 +748 -77
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +29 -1150
- 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 +80 -25
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +165 -83
- 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 +75 -193
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +80 -298
- package/dist/Budgets/ManagedBudget.js.map +1 -1
- package/dist/Budgets/VestingBudget.d.ts +223 -89
- 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 +5 -7
- 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 +28 -25
- 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 +38 -16
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +42 -29
- 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 +234 -21
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +45 -32
- package/dist/Incentives/CGDAIncentive.js.map +1 -1
- package/dist/Incentives/ERC1155Incentive.d.ts +224 -37
- 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 +230 -29
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +56 -43
- package/dist/Incentives/ERC20Incentive.js.map +1 -1
- package/dist/{Budgets/SimpleBudget.d.ts → Incentives/ERC20VariableCriteriaIncentive.d.ts} +335 -440
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +231 -29
- 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 -296
- 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 +40 -18
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
- package/dist/Incentives/PointsIncentive.js +37 -24
- 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 +16 -16
- package/dist/Validators/SignerValidator.d.ts.map +1 -1
- package/dist/Validators/SignerValidator.js +30 -27
- 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.map +1 -1
- package/dist/claiming.d.ts +1 -1
- package/dist/claiming.js.map +1 -1
- 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 +256 -20
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +183 -26
- package/dist/errors.js.map +1 -1
- package/dist/{generated-57_Kffpz.js → generated-CKt2yCQd.js} +3613 -1869
- 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 +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +142 -108
- package/dist/index.js.map +1 -1
- package/dist/transfers.cjs.map +1 -1
- package/dist/transfers.d.ts +1 -1
- package/dist/transfers.js.map +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +26 -12
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +38 -23
- package/dist/utils.js.map +1 -1
- package/package.json +20 -10
- package/src/Actions/Action.test.ts +14 -13
- package/src/Actions/ContractAction.test.ts +10 -10
- package/src/Actions/ContractAction.ts +11 -12
- package/src/Actions/ERC721MintAction.test.ts +6 -6
- package/src/Actions/ERC721MintAction.ts +14 -15
- package/src/Actions/EventAction.test.ts +729 -109
- package/src/Actions/EventAction.ts +542 -84
- 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 +39 -61
- package/src/AllowLists/SimpleDenyList.test.ts +4 -4
- package/src/AllowLists/SimpleDenyList.ts +40 -17
- package/src/Auth/PassthroughAuth.test.ts +1 -1
- package/src/Boost.ts +21 -24
- package/src/BoostCore.test.ts +323 -268
- package/src/BoostCore.ts +396 -219
- package/src/BoostRegistry.test.ts +53 -0
- package/src/BoostRegistry.ts +161 -40
- 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 +48 -310
- package/src/Budgets/VestingBudget.test.ts +7 -7
- package/src/Budgets/VestingBudget.ts +34 -106
- package/src/Deployable/Contract.ts +4 -5
- package/src/Deployable/Deployable.ts +1 -1
- package/src/Deployable/DeployableTarget.ts +30 -19
- package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
- package/src/Incentives/AllowListIncentive.test.ts +5 -5
- package/src/Incentives/AllowListIncentive.ts +29 -15
- package/src/Incentives/CGDAIncentive.test.ts +9 -6
- package/src/Incentives/CGDAIncentive.ts +38 -18
- package/src/Incentives/ERC1155Incentive.test.ts +3 -3
- package/src/Incentives/ERC1155Incentive.ts +28 -29
- package/src/Incentives/ERC20Incentive.test.ts +9 -6
- package/src/Incentives/ERC20Incentive.ts +46 -26
- package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +324 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +8 -11
- package/src/Incentives/ERC20VariableIncentive.ts +49 -26
- package/src/Incentives/Incentive.test.ts +4 -1
- package/src/Incentives/Incentive.ts +7 -6
- package/src/Incentives/PointsIncentive.test.ts +24 -25
- package/src/Incentives/PointsIncentive.ts +31 -17
- package/src/Validators/SignerValidator.test.ts +6 -6
- package/src/Validators/SignerValidator.ts +19 -17
- package/src/Validators/Validator.test.ts +2 -2
- package/src/Validators/Validator.ts +1 -1
- package/src/claiming.ts +1 -1
- package/src/errors.ts +345 -21
- package/src/index.test.ts +118 -36
- package/src/index.ts +5 -0
- package/src/transfers.ts +1 -1
- package/src/utils.test.ts +2 -2
- package/src/utils.ts +61 -12
- 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-57_Kffpz.js.map +0 -1
- package/dist/generated-wKBNvm48.cjs +0 -3
- package/dist/generated-wKBNvm48.cjs.map +0 -1
- package/src/Budgets/SimpleBudget.test.ts +0 -152
- package/src/Budgets/SimpleBudget.ts +0 -564
|
@@ -7,29 +7,52 @@ 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,
|
|
17
33
|
encodeAbiParameters,
|
|
34
|
+
fromHex,
|
|
35
|
+
isAddress,
|
|
18
36
|
isAddressEqual,
|
|
37
|
+
zeroHash,
|
|
19
38
|
} from 'viem';
|
|
20
|
-
import {
|
|
39
|
+
import { EventAction as EventActionBases } from '../../dist/deployments.json';
|
|
21
40
|
import type {
|
|
22
41
|
DeployableOptions,
|
|
23
42
|
GenericDeployableParams,
|
|
24
43
|
} from '../Deployable/Deployable';
|
|
25
44
|
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
26
45
|
import {
|
|
46
|
+
DecodedArgsMalformedError,
|
|
27
47
|
FieldValueNotComparableError,
|
|
28
48
|
FieldValueUndefinedError,
|
|
49
|
+
FunctionDataDecodeError,
|
|
29
50
|
InvalidNumericalCriteriaError,
|
|
30
51
|
NoEventActionStepsProvidedError,
|
|
31
52
|
TooManyEventActionStepsProvidedError,
|
|
53
|
+
UnparseableAbiParamError,
|
|
32
54
|
UnrecognizedFilterTypeError,
|
|
55
|
+
ValidationAbiMissingError,
|
|
33
56
|
} from '../errors';
|
|
34
57
|
import {
|
|
35
58
|
type GetLogsParams,
|
|
@@ -55,6 +78,7 @@ export enum FilterType {
|
|
|
55
78
|
GREATER_THAN = 2,
|
|
56
79
|
LESS_THAN = 3,
|
|
57
80
|
CONTAINS = 4,
|
|
81
|
+
REGEX = 5,
|
|
58
82
|
}
|
|
59
83
|
|
|
60
84
|
/**
|
|
@@ -198,6 +222,22 @@ export interface ActionStep {
|
|
|
198
222
|
*/
|
|
199
223
|
actionParameter: Criteria;
|
|
200
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
|
+
|
|
201
241
|
/**
|
|
202
242
|
* You can either supply a simplified version of the payload, or one that explicitly declares action steps.
|
|
203
243
|
*
|
|
@@ -280,6 +320,24 @@ export interface EventActionPayloadRaw {
|
|
|
280
320
|
actionStepFour: ActionStep;
|
|
281
321
|
}
|
|
282
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>;
|
|
340
|
+
|
|
283
341
|
/**
|
|
284
342
|
* A generic event action
|
|
285
343
|
*
|
|
@@ -305,9 +363,11 @@ export class EventAction extends DeployableTarget<
|
|
|
305
363
|
*
|
|
306
364
|
* @public
|
|
307
365
|
* @static
|
|
308
|
-
* @type {Address}
|
|
366
|
+
* @type {Record<number, Address>}
|
|
309
367
|
*/
|
|
310
|
-
public static override
|
|
368
|
+
public static override bases: Record<number, Address> = {
|
|
369
|
+
...(EventActionBases as Record<number, Address>),
|
|
370
|
+
};
|
|
311
371
|
/**
|
|
312
372
|
* @inheritdoc
|
|
313
373
|
*
|
|
@@ -323,12 +383,12 @@ export class EventAction extends DeployableTarget<
|
|
|
323
383
|
* @public
|
|
324
384
|
* @async
|
|
325
385
|
* @param {number} index The index of the action event to retrieve
|
|
326
|
-
* @param {?
|
|
386
|
+
* @param {?ReadEventActionParams<'getActionStep'>} [params]
|
|
327
387
|
* @returns {Promise<ActionStep>}
|
|
328
388
|
*/
|
|
329
389
|
public async getActionStep(
|
|
330
390
|
index: number,
|
|
331
|
-
params?:
|
|
391
|
+
params?: ReadEventActionParams<'getActionStep'>,
|
|
332
392
|
) {
|
|
333
393
|
const steps = await this.getActionSteps(params);
|
|
334
394
|
return steps.at(index);
|
|
@@ -339,11 +399,11 @@ export class EventAction extends DeployableTarget<
|
|
|
339
399
|
*
|
|
340
400
|
* @public
|
|
341
401
|
* @async
|
|
342
|
-
* @param {?
|
|
402
|
+
* @param {?ReadEventActionParams<'getActionSteps'>} [params]
|
|
343
403
|
* @returns {Promise<ActionStep[]>}
|
|
344
404
|
*/
|
|
345
405
|
public async getActionSteps(
|
|
346
|
-
params?:
|
|
406
|
+
params?: ReadEventActionParams<'getActionSteps'>,
|
|
347
407
|
) {
|
|
348
408
|
const steps = (await readEventActionGetActionSteps(this._config, {
|
|
349
409
|
address: this.assertValidAddress(),
|
|
@@ -359,11 +419,11 @@ export class EventAction extends DeployableTarget<
|
|
|
359
419
|
*
|
|
360
420
|
* @public
|
|
361
421
|
* @async
|
|
362
|
-
* @param {?
|
|
422
|
+
* @param {?ReadEventActionParams<'getActionStepsCount'>} [params]
|
|
363
423
|
* @returns {Promise<bigint>}
|
|
364
424
|
*/
|
|
365
425
|
public async getActionStepsCount(
|
|
366
|
-
params?:
|
|
426
|
+
params?: ReadEventActionParams<'getActionStepsCount'>,
|
|
367
427
|
) {
|
|
368
428
|
const steps = await this.getActionSteps(params);
|
|
369
429
|
return steps.length;
|
|
@@ -374,17 +434,16 @@ export class EventAction extends DeployableTarget<
|
|
|
374
434
|
*
|
|
375
435
|
* @public
|
|
376
436
|
* @async
|
|
377
|
-
* @param {?
|
|
437
|
+
* @param {?ReadEventActionParams<'getActionClaimant'>} [params]
|
|
378
438
|
* @returns {Promise<ActionClaimant>}
|
|
379
439
|
*/
|
|
380
440
|
public async getActionClaimant(
|
|
381
|
-
params?:
|
|
382
|
-
) {
|
|
441
|
+
params?: ReadEventActionParams<'getActionClaimant'>,
|
|
442
|
+
): Promise<ActionClaimant> {
|
|
383
443
|
const result = (await readEventActionGetActionClaimant(this._config, {
|
|
384
444
|
address: this.assertValidAddress(),
|
|
385
445
|
...this.optionallyAttachAccount(),
|
|
386
|
-
|
|
387
|
-
...(params as any),
|
|
446
|
+
...params,
|
|
388
447
|
})) as RawActionClaimant;
|
|
389
448
|
return _fromRawActionStep(result);
|
|
390
449
|
}
|
|
@@ -395,7 +454,7 @@ export class EventAction extends DeployableTarget<
|
|
|
395
454
|
* @public
|
|
396
455
|
* @async
|
|
397
456
|
* @param {Hex} data
|
|
398
|
-
* @param {?WriteParams
|
|
457
|
+
* @param {?WriteParams} [params]
|
|
399
458
|
* @returns {Promise<readonly [boolean, `0x${string}`]>}
|
|
400
459
|
*/
|
|
401
460
|
public async execute(
|
|
@@ -411,8 +470,8 @@ export class EventAction extends DeployableTarget<
|
|
|
411
470
|
* @public
|
|
412
471
|
* @async
|
|
413
472
|
* @param {Hex} data
|
|
414
|
-
* @param {?WriteParams
|
|
415
|
-
* @returns {
|
|
473
|
+
* @param {?WriteParams} [params]
|
|
474
|
+
* @returns {Promise<{ hash: `0x${string}`; result: readonly [boolean, `0x${string}`]; }>}
|
|
416
475
|
*/
|
|
417
476
|
public async executeRaw(
|
|
418
477
|
data: Hex,
|
|
@@ -429,27 +488,154 @@ export class EventAction extends DeployableTarget<
|
|
|
429
488
|
return { hash, result };
|
|
430
489
|
}
|
|
431
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
|
+
|
|
432
628
|
/**
|
|
433
629
|
* Retrieves action steps, and uses them to validate against, and optionally fetch logs that match the step's signature.
|
|
434
630
|
* If logs are provided in the optional `params` argument, then those logs will be used instead of fetched with the configured client.
|
|
435
631
|
*
|
|
436
632
|
* @public
|
|
437
633
|
* @async
|
|
438
|
-
* @param
|
|
439
|
-
* GetLogsParams<Abi, ContractEventName<Abi>> & {
|
|
440
|
-
* knownEvents?: Record<Hex, AbiEvent>;
|
|
441
|
-
* logs?: Log[];
|
|
442
|
-
* }} [params]
|
|
634
|
+
* @param ValidateActionStepParams params
|
|
443
635
|
* @returns {Promise<boolean>}
|
|
444
636
|
*/
|
|
445
|
-
public async validateActionSteps(
|
|
446
|
-
|
|
447
|
-
GetLogsParams<Abi, ContractEventName<Abi>> & {
|
|
448
|
-
knownEvents?: Record<Hex, AbiEvent>;
|
|
449
|
-
logs?: Log[];
|
|
450
|
-
},
|
|
451
|
-
) {
|
|
452
|
-
const actionSteps = await this.getActionSteps(params);
|
|
637
|
+
public async validateActionSteps(params: ValidateActionStepParams) {
|
|
638
|
+
const actionSteps = await this.getActionSteps();
|
|
453
639
|
for (const actionStep of actionSteps) {
|
|
454
640
|
if (!(await this.isActionStepValid(actionStep, params))) {
|
|
455
641
|
return false;
|
|
@@ -459,108 +645,341 @@ export class EventAction extends DeployableTarget<
|
|
|
459
645
|
}
|
|
460
646
|
|
|
461
647
|
/**
|
|
462
|
-
* Validates a single action step with a given criteria against logs.
|
|
463
|
-
* 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.
|
|
464
651
|
*
|
|
465
652
|
* @public
|
|
466
653
|
* @async
|
|
467
|
-
* @param {ActionStep} actionStep
|
|
468
|
-
* @param {
|
|
469
|
-
* knownEvents?: Record<Hex, AbiEvent>;
|
|
470
|
-
* logs?: Log[];
|
|
471
|
-
* }} [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.
|
|
472
656
|
* @returns {Promise<boolean>}
|
|
473
657
|
*/
|
|
474
658
|
public async isActionStepValid(
|
|
475
659
|
actionStep: ActionStep,
|
|
476
|
-
params
|
|
477
|
-
knownEvents?: Record<Hex, AbiEvent>;
|
|
478
|
-
logs?: Log[];
|
|
479
|
-
},
|
|
660
|
+
params: ValidateActionStepParams,
|
|
480
661
|
) {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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);
|
|
489
708
|
}
|
|
490
|
-
if (
|
|
491
|
-
|
|
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
|
+
}
|
|
492
719
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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;
|
|
503
735
|
if (!logs.length) return false;
|
|
504
736
|
for (let log of logs) {
|
|
505
|
-
if (
|
|
506
|
-
return
|
|
737
|
+
if (this.validateLogAgainstCriteria(criteria, log)) {
|
|
738
|
+
return true;
|
|
507
739
|
}
|
|
508
740
|
}
|
|
509
|
-
return
|
|
741
|
+
return false;
|
|
510
742
|
}
|
|
511
743
|
|
|
512
744
|
/**
|
|
513
|
-
* 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.
|
|
514
806
|
*
|
|
515
807
|
* @param {Criteria} criteria - The criteria to validate against.
|
|
516
|
-
* @param {
|
|
517
|
-
* @
|
|
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.
|
|
518
813
|
*/
|
|
519
|
-
public
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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;
|
|
523
827
|
}
|
|
828
|
+
|
|
524
829
|
// Type narrow based on criteria.filterType
|
|
525
830
|
switch (criteria.filterType) {
|
|
526
831
|
case FilterType.EQUAL:
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
criteria.filterData,
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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);
|
|
534
845
|
|
|
535
846
|
case FilterType.NOT_EQUAL:
|
|
536
|
-
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);
|
|
537
861
|
|
|
538
862
|
case FilterType.GREATER_THAN:
|
|
539
863
|
if (criteria.fieldType === PrimitiveType.UINT) {
|
|
540
864
|
return BigInt(fieldValue) > BigInt(criteria.filterData);
|
|
541
865
|
}
|
|
542
|
-
throw new InvalidNumericalCriteriaError({
|
|
866
|
+
throw new InvalidNumericalCriteriaError({
|
|
867
|
+
...input,
|
|
868
|
+
criteria,
|
|
869
|
+
fieldValue,
|
|
870
|
+
});
|
|
543
871
|
|
|
544
872
|
case FilterType.LESS_THAN:
|
|
545
873
|
if (criteria.fieldType === PrimitiveType.UINT) {
|
|
546
874
|
return BigInt(fieldValue) < BigInt(criteria.filterData);
|
|
547
875
|
}
|
|
548
|
-
throw new InvalidNumericalCriteriaError({
|
|
876
|
+
throw new InvalidNumericalCriteriaError({
|
|
877
|
+
...input,
|
|
878
|
+
criteria,
|
|
879
|
+
fieldValue,
|
|
880
|
+
});
|
|
549
881
|
|
|
550
882
|
case FilterType.CONTAINS:
|
|
551
883
|
if (
|
|
552
884
|
criteria.fieldType === PrimitiveType.BYTES ||
|
|
553
885
|
criteria.fieldType === PrimitiveType.STRING
|
|
554
886
|
) {
|
|
555
|
-
|
|
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);
|
|
556
915
|
}
|
|
557
|
-
throw new FieldValueNotComparableError({ log, criteria, fieldValue });
|
|
558
916
|
|
|
559
917
|
default:
|
|
560
|
-
throw new UnrecognizedFilterTypeError({
|
|
918
|
+
throw new UnrecognizedFilterTypeError({
|
|
919
|
+
...input,
|
|
920
|
+
criteria,
|
|
921
|
+
fieldValue,
|
|
922
|
+
});
|
|
561
923
|
}
|
|
562
924
|
}
|
|
563
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
|
+
});
|
|
977
|
+
}
|
|
978
|
+
return this.validateFieldAgainstCriteria(criteria, fieldValue, {
|
|
979
|
+
decodedArgs,
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
|
|
564
983
|
/**
|
|
565
984
|
* @inheritdoc
|
|
566
985
|
*
|
|
@@ -609,6 +1028,17 @@ export class EventAction extends DeployableTarget<
|
|
|
609
1028
|
...this.optionallyAttachAccount(options.account),
|
|
610
1029
|
};
|
|
611
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
|
+
}
|
|
612
1042
|
}
|
|
613
1043
|
|
|
614
1044
|
function _dedupeActionSteps(_steps: ActionStep[]): ActionStep[] {
|
|
@@ -803,3 +1233,31 @@ export function prepareEventActionPayload({
|
|
|
803
1233
|
],
|
|
804
1234
|
);
|
|
805
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
|
+
};
|
|
1263
|
+
}
|