@boostxyz/sdk 0.0.0-alpha.2 → 0.0.0-alpha.21

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