@boostxyz/sdk 0.0.0-alpha.10

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 (242) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +7 -0
  3. package/dist/Actions/Action.cjs +2 -0
  4. package/dist/Actions/Action.cjs.map +1 -0
  5. package/dist/Actions/Action.d.ts +31 -0
  6. package/dist/Actions/Action.d.ts.map +1 -0
  7. package/dist/Actions/Action.js +29 -0
  8. package/dist/Actions/Action.js.map +1 -0
  9. package/dist/Actions/ContractAction.d.ts +370 -0
  10. package/dist/Actions/ContractAction.d.ts.map +1 -0
  11. package/dist/Actions/ERC721MintAction.d.ts +513 -0
  12. package/dist/Actions/ERC721MintAction.d.ts.map +1 -0
  13. package/dist/Actions/EventAction.cjs +2 -0
  14. package/dist/Actions/EventAction.cjs.map +1 -0
  15. package/dist/Actions/EventAction.d.ts +694 -0
  16. package/dist/Actions/EventAction.d.ts.map +1 -0
  17. package/dist/Actions/EventAction.js +491 -0
  18. package/dist/Actions/EventAction.js.map +1 -0
  19. package/dist/AllowLists/AllowList.cjs +2 -0
  20. package/dist/AllowLists/AllowList.cjs.map +1 -0
  21. package/dist/AllowLists/AllowList.d.ts +32 -0
  22. package/dist/AllowLists/AllowList.d.ts.map +1 -0
  23. package/dist/AllowLists/AllowList.js +30 -0
  24. package/dist/AllowLists/AllowList.js.map +1 -0
  25. package/dist/AllowLists/SimpleAllowList.cjs +2 -0
  26. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  27. package/dist/AllowLists/SimpleAllowList.d.ts +481 -0
  28. package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -0
  29. package/dist/AllowLists/SimpleAllowList.js +154 -0
  30. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  31. package/dist/AllowLists/SimpleDenyList.cjs +2 -0
  32. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  33. package/dist/AllowLists/SimpleDenyList.d.ts +335 -0
  34. package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -0
  35. package/dist/AllowLists/SimpleDenyList.js +115 -0
  36. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  37. package/dist/Auth/Auth.cjs +2 -0
  38. package/dist/Auth/Auth.cjs.map +1 -0
  39. package/dist/Auth/Auth.d.ts +10 -0
  40. package/dist/Auth/Auth.d.ts.map +1 -0
  41. package/dist/Auth/Auth.js +5 -0
  42. package/dist/Auth/Auth.js.map +1 -0
  43. package/dist/Auth/PassthroughAuth.cjs +2 -0
  44. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  45. package/dist/Auth/PassthroughAuth.d.ts +51 -0
  46. package/dist/Auth/PassthroughAuth.d.ts.map +1 -0
  47. package/dist/Auth/PassthroughAuth.js +39 -0
  48. package/dist/Auth/PassthroughAuth.js.map +1 -0
  49. package/dist/Boost.cjs +2 -0
  50. package/dist/Boost.cjs.map +1 -0
  51. package/dist/Boost.d.ts +234 -0
  52. package/dist/Boost.d.ts.map +1 -0
  53. package/dist/Boost.js +162 -0
  54. package/dist/Boost.js.map +1 -0
  55. package/dist/BoostCore.cjs +3 -0
  56. package/dist/BoostCore.cjs.map +1 -0
  57. package/dist/BoostCore.d.ts +498 -0
  58. package/dist/BoostCore.d.ts.map +1 -0
  59. package/dist/BoostCore.js +1153 -0
  60. package/dist/BoostCore.js.map +1 -0
  61. package/dist/BoostRegistry.cjs +2 -0
  62. package/dist/BoostRegistry.cjs.map +1 -0
  63. package/dist/BoostRegistry.d.ts +243 -0
  64. package/dist/BoostRegistry.d.ts.map +1 -0
  65. package/dist/BoostRegistry.js +262 -0
  66. package/dist/BoostRegistry.js.map +1 -0
  67. package/dist/Budgets/Budget.cjs +2 -0
  68. package/dist/Budgets/Budget.cjs.map +1 -0
  69. package/dist/Budgets/Budget.d.ts +31 -0
  70. package/dist/Budgets/Budget.d.ts.map +1 -0
  71. package/dist/Budgets/Budget.js +29 -0
  72. package/dist/Budgets/Budget.js.map +1 -0
  73. package/dist/Budgets/ManagedBudget.cjs +2 -0
  74. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  75. package/dist/Budgets/ManagedBudget.d.ts +1103 -0
  76. package/dist/Budgets/ManagedBudget.d.ts.map +1 -0
  77. package/dist/Budgets/ManagedBudget.js +516 -0
  78. package/dist/Budgets/ManagedBudget.js.map +1 -0
  79. package/dist/Budgets/SimpleBudget.d.ts +824 -0
  80. package/dist/Budgets/SimpleBudget.d.ts.map +1 -0
  81. package/dist/Budgets/VestingBudget.d.ts +778 -0
  82. package/dist/Budgets/VestingBudget.d.ts.map +1 -0
  83. package/dist/Deployable/Contract.cjs +2 -0
  84. package/dist/Deployable/Contract.cjs.map +1 -0
  85. package/dist/Deployable/Contract.d.ts +125 -0
  86. package/dist/Deployable/Contract.d.ts.map +1 -0
  87. package/dist/Deployable/Contract.js +150 -0
  88. package/dist/Deployable/Contract.js.map +1 -0
  89. package/dist/Deployable/Deployable.cjs +2 -0
  90. package/dist/Deployable/Deployable.cjs.map +1 -0
  91. package/dist/Deployable/Deployable.d.ts +161 -0
  92. package/dist/Deployable/Deployable.d.ts.map +1 -0
  93. package/dist/Deployable/Deployable.js +131 -0
  94. package/dist/Deployable/Deployable.js.map +1 -0
  95. package/dist/Deployable/DeployableTarget.cjs +2 -0
  96. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  97. package/dist/Deployable/DeployableTarget.d.ts +116 -0
  98. package/dist/Deployable/DeployableTarget.d.ts.map +1 -0
  99. package/dist/Deployable/DeployableTarget.js +132 -0
  100. package/dist/Deployable/DeployableTarget.js.map +1 -0
  101. package/dist/Incentives/AllowListIncentive.cjs +2 -0
  102. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  103. package/dist/Incentives/AllowListIncentive.d.ts +513 -0
  104. package/dist/Incentives/AllowListIncentive.d.ts.map +1 -0
  105. package/dist/Incentives/AllowListIncentive.js +201 -0
  106. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  107. package/dist/Incentives/CGDAIncentive.cjs +2 -0
  108. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  109. package/dist/Incentives/CGDAIncentive.d.ts +644 -0
  110. package/dist/Incentives/CGDAIncentive.d.ts.map +1 -0
  111. package/dist/Incentives/CGDAIncentive.js +271 -0
  112. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  113. package/dist/Incentives/ERC1155Incentive.d.ts +713 -0
  114. package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -0
  115. package/dist/Incentives/ERC20Incentive.cjs +2 -0
  116. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  117. package/dist/Incentives/ERC20Incentive.d.ts +666 -0
  118. package/dist/Incentives/ERC20Incentive.d.ts.map +1 -0
  119. package/dist/Incentives/ERC20Incentive.js +312 -0
  120. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  121. package/dist/Incentives/ERC20VariableIncentive.d.ts +582 -0
  122. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -0
  123. package/dist/Incentives/Incentive.cjs +2 -0
  124. package/dist/Incentives/Incentive.cjs.map +1 -0
  125. package/dist/Incentives/Incentive.d.ts +36 -0
  126. package/dist/Incentives/Incentive.d.ts.map +1 -0
  127. package/dist/Incentives/Incentive.js +299 -0
  128. package/dist/Incentives/Incentive.js.map +1 -0
  129. package/dist/Incentives/PointsIncentive.cjs +2 -0
  130. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  131. package/dist/Incentives/PointsIncentive.d.ts +659 -0
  132. package/dist/Incentives/PointsIncentive.d.ts.map +1 -0
  133. package/dist/Incentives/PointsIncentive.js +215 -0
  134. package/dist/Incentives/PointsIncentive.js.map +1 -0
  135. package/dist/Validators/SignerValidator.cjs +2 -0
  136. package/dist/Validators/SignerValidator.cjs.map +1 -0
  137. package/dist/Validators/SignerValidator.d.ts +745 -0
  138. package/dist/Validators/SignerValidator.d.ts.map +1 -0
  139. package/dist/Validators/SignerValidator.js +293 -0
  140. package/dist/Validators/SignerValidator.js.map +1 -0
  141. package/dist/Validators/Validator.cjs +2 -0
  142. package/dist/Validators/Validator.cjs.map +1 -0
  143. package/dist/Validators/Validator.d.ts +31 -0
  144. package/dist/Validators/Validator.d.ts.map +1 -0
  145. package/dist/Validators/Validator.js +27 -0
  146. package/dist/Validators/Validator.js.map +1 -0
  147. package/dist/claiming.cjs +2 -0
  148. package/dist/claiming.cjs.map +1 -0
  149. package/dist/claiming.d.ts +43 -0
  150. package/dist/claiming.d.ts.map +1 -0
  151. package/dist/claiming.js +17 -0
  152. package/dist/claiming.js.map +1 -0
  153. package/dist/componentInterfaces-CKCBwG16.cjs +2 -0
  154. package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
  155. package/dist/componentInterfaces-DYkaxBda.js +13 -0
  156. package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
  157. package/dist/errors.cjs +2 -0
  158. package/dist/errors.cjs.map +1 -0
  159. package/dist/errors.d.ts +441 -0
  160. package/dist/errors.d.ts.map +1 -0
  161. package/dist/errors.js +262 -0
  162. package/dist/errors.js.map +1 -0
  163. package/dist/generated-BDeDiaCK.js +4625 -0
  164. package/dist/generated-BDeDiaCK.js.map +1 -0
  165. package/dist/generated-wKBNvm48.cjs +3 -0
  166. package/dist/generated-wKBNvm48.cjs.map +1 -0
  167. package/dist/index.cjs +2 -0
  168. package/dist/index.cjs.map +1 -0
  169. package/dist/index.d.ts +25 -0
  170. package/dist/index.d.ts.map +1 -0
  171. package/dist/index.js +113 -0
  172. package/dist/index.js.map +1 -0
  173. package/dist/transfers.cjs +2 -0
  174. package/dist/transfers.cjs.map +1 -0
  175. package/dist/transfers.d.ts +198 -0
  176. package/dist/transfers.d.ts.map +1 -0
  177. package/dist/transfers.js +84 -0
  178. package/dist/transfers.js.map +1 -0
  179. package/dist/utils.cjs +2 -0
  180. package/dist/utils.cjs.map +1 -0
  181. package/dist/utils.d.ts +116 -0
  182. package/dist/utils.d.ts.map +1 -0
  183. package/dist/utils.js +30 -0
  184. package/dist/utils.js.map +1 -0
  185. package/package.json +211 -0
  186. package/src/Actions/Action.test.ts +75 -0
  187. package/src/Actions/Action.ts +61 -0
  188. package/src/Actions/ContractAction.test.ts +197 -0
  189. package/src/Actions/ContractAction.ts +301 -0
  190. package/src/Actions/ERC721MintAction.test.ts +112 -0
  191. package/src/Actions/ERC721MintAction.ts +292 -0
  192. package/src/Actions/EventAction.test.ts +205 -0
  193. package/src/Actions/EventAction.ts +811 -0
  194. package/src/AllowLists/AllowList.test.ts +64 -0
  195. package/src/AllowLists/AllowList.ts +60 -0
  196. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  197. package/src/AllowLists/SimpleAllowList.ts +284 -0
  198. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  199. package/src/AllowLists/SimpleDenyList.ts +227 -0
  200. package/src/Auth/Auth.ts +11 -0
  201. package/src/Auth/PassthroughAuth.test.ts +12 -0
  202. package/src/Auth/PassthroughAuth.ts +80 -0
  203. package/src/Boost.ts +290 -0
  204. package/src/BoostCore.test.ts +773 -0
  205. package/src/BoostCore.ts +1261 -0
  206. package/src/BoostRegistry.ts +467 -0
  207. package/src/Budgets/Budget.test.ts +27 -0
  208. package/src/Budgets/Budget.ts +61 -0
  209. package/src/Budgets/ManagedBudget.test.ts +154 -0
  210. package/src/Budgets/ManagedBudget.ts +796 -0
  211. package/src/Budgets/SimpleBudget.test.ts +152 -0
  212. package/src/Budgets/SimpleBudget.ts +564 -0
  213. package/src/Budgets/VestingBudget.test.ts +123 -0
  214. package/src/Budgets/VestingBudget.ts +602 -0
  215. package/src/Deployable/Contract.ts +229 -0
  216. package/src/Deployable/Deployable.ts +250 -0
  217. package/src/Deployable/DeployableTarget.ts +223 -0
  218. package/src/Incentives/AllowListIncentive.test.ts +143 -0
  219. package/src/Incentives/AllowListIncentive.ts +334 -0
  220. package/src/Incentives/CGDAIncentive.test.ts +132 -0
  221. package/src/Incentives/CGDAIncentive.ts +468 -0
  222. package/src/Incentives/ERC1155Incentive.test.ts +87 -0
  223. package/src/Incentives/ERC1155Incentive.ts +466 -0
  224. package/src/Incentives/ERC20Incentive.test.ts +130 -0
  225. package/src/Incentives/ERC20Incentive.ts +482 -0
  226. package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
  227. package/src/Incentives/ERC20VariableIncentive.ts +420 -0
  228. package/src/Incentives/Incentive.test.ts +92 -0
  229. package/src/Incentives/Incentive.ts +85 -0
  230. package/src/Incentives/PointsIncentive.test.ts +139 -0
  231. package/src/Incentives/PointsIncentive.ts +365 -0
  232. package/src/Validators/SignerValidator.test.ts +159 -0
  233. package/src/Validators/SignerValidator.ts +681 -0
  234. package/src/Validators/Validator.test.ts +21 -0
  235. package/src/Validators/Validator.ts +55 -0
  236. package/src/claiming.ts +56 -0
  237. package/src/errors.ts +542 -0
  238. package/src/index.test.ts +40 -0
  239. package/src/index.ts +53 -0
  240. package/src/transfers.ts +284 -0
  241. package/src/utils.test.ts +44 -0
  242. package/src/utils.ts +198 -0
@@ -0,0 +1,811 @@
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 {
11
+ type Abi,
12
+ type AbiEvent,
13
+ type Address,
14
+ type ContractEventName,
15
+ type Hex,
16
+ type Log,
17
+ encodeAbiParameters,
18
+ isAddressEqual,
19
+ } from 'viem';
20
+ import { getLogs } from 'viem/actions';
21
+ import type {
22
+ DeployableOptions,
23
+ GenericDeployableParams,
24
+ } from '../Deployable/Deployable';
25
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
26
+ import {
27
+ FieldValueNotComparableError,
28
+ FieldValueUndefinedError,
29
+ InvalidNumericalCriteriaError,
30
+ NoEventActionStepsProvidedError,
31
+ TooManyEventActionStepsProvidedError,
32
+ UnrecognizedFilterTypeError,
33
+ } from '../errors';
34
+ import {
35
+ type GetLogsParams,
36
+ type Overwrite,
37
+ type ReadParams,
38
+ RegistryType,
39
+ type WriteParams,
40
+ } from '../utils';
41
+
42
+ /*
43
+ * Action Event Payloads
44
+ */
45
+
46
+ /**
47
+ * Filter types used to determine how criteria are evaluated.
48
+ *
49
+ * @export
50
+ * @enum {number}
51
+ */
52
+ export enum FilterType {
53
+ EQUAL = 0,
54
+ NOT_EQUAL = 1,
55
+ GREATER_THAN = 2,
56
+ LESS_THAN = 3,
57
+ CONTAINS = 4,
58
+ }
59
+
60
+ /**
61
+ * The primitive types supported for filtering.
62
+ *
63
+ * @export
64
+ * @enum {number}
65
+ */
66
+ export enum PrimitiveType {
67
+ UINT = 0,
68
+ ADDRESS = 1,
69
+ BYTES = 2,
70
+ STRING = 3,
71
+ }
72
+
73
+ /**
74
+ * Object representation of a `Criteria` struct used in event actions.
75
+ *
76
+ * @export
77
+ * @interface Criteria
78
+ * @typedef {Criteria}
79
+ */
80
+ export interface Criteria {
81
+ /**
82
+ * The filter type used in this criteria.
83
+ *
84
+ * @type {FilterType}
85
+ */
86
+ filterType: FilterType;
87
+ /**
88
+ * The primitive type of the field being filtered.
89
+ *
90
+ * @type {PrimitiveType}
91
+ */
92
+ fieldType: PrimitiveType;
93
+ /**
94
+ * The index in the logs argument array where the field is located.
95
+ *
96
+ * @type {number}
97
+ */
98
+ fieldIndex: number;
99
+ /**
100
+ * The filter data used for complex filtering.
101
+ *
102
+ * @type {Hex}
103
+ */
104
+ filterData: Hex;
105
+ }
106
+
107
+ /**
108
+ * Whether a given signature is an event or function
109
+ *
110
+ * @export
111
+ * @enum {number}
112
+ */
113
+ export enum SignatureType {
114
+ EVENT = 0,
115
+ FUNC = 1,
116
+ }
117
+
118
+ /**
119
+ * The payload describing how claimants are identified
120
+ *
121
+ * @export
122
+ * @interface ActionClaimant
123
+ * @typedef {ActionClaimant}
124
+ */
125
+ export interface ActionClaimant {
126
+ /**
127
+ * Whether claimaint is inferred from event or function
128
+ *
129
+ * @type {SignatureType}
130
+ */
131
+ signatureType: SignatureType;
132
+ /**
133
+ * The 4 byte signature of the event or function
134
+ *
135
+ * @type {Hex}
136
+ */
137
+ signature: Hex;
138
+ /**
139
+ * The index corresponding to claimant.
140
+ *
141
+ * @type {number}
142
+ */
143
+ fieldIndex: number;
144
+ /**
145
+ * The address of the target contract
146
+ *
147
+ * @type {Address}
148
+ */
149
+ targetContract: Address;
150
+ /**
151
+ * The chain id of the target contract.
152
+ * @type {number}
153
+ */
154
+ chainid: number;
155
+ }
156
+
157
+ /**
158
+ * Object representation of an `ActionStep` struct used in event actions.
159
+ *
160
+ * @export
161
+ * @interface ActionStep
162
+ * @typedef {ActionStep}
163
+ */
164
+ export interface ActionStep {
165
+ /**
166
+ * The signature of the event.
167
+ *
168
+ * @type {Hex}
169
+ */
170
+ signature: Hex;
171
+ /**
172
+ * Whether claimaint is inferred from event or function
173
+ *
174
+ * @type {SignatureType}
175
+ */
176
+ signatureType: SignatureType;
177
+ /**
178
+ * The type of action being performed.
179
+ *
180
+ * @type {number}
181
+ */
182
+ actionType?: number;
183
+ /**
184
+ * The address of the target contract.
185
+ *
186
+ * @type {Address}
187
+ */
188
+ targetContract: Address;
189
+ /**
190
+ * The chain id of the target contract.
191
+ * @type {number}
192
+ */
193
+ chainid: number;
194
+ /**
195
+ * The criteria used for this action step.
196
+ *
197
+ * @type {Criteria}
198
+ */
199
+ actionParameter: Criteria;
200
+ }
201
+ /**
202
+ * You can either supply a simplified version of the payload, or one that explicitly declares action steps.
203
+ *
204
+ * @export
205
+ * @typedef {EventActionPayload}
206
+ */
207
+ export type EventActionPayload =
208
+ | EventActionPayloadSimple
209
+ | EventActionPayloadRaw;
210
+
211
+ export interface EventActionPayloadSimple {
212
+ /**
213
+ * The payload describing how claimants are identified
214
+ *
215
+ * @type {ActionClaimant}
216
+ */
217
+ actionClaimant: ActionClaimant;
218
+
219
+ /**
220
+ * Up to 4 action steps.
221
+ * If you supply less than 4, then the last step will be reused to satisfy the EventAction.InitPayload
222
+ * Any more than 4 will throw an error.
223
+ *
224
+ * @type {ActionStep[]}
225
+ */
226
+ actionSteps: ActionStep[];
227
+ }
228
+
229
+ export type ActionStepTuple = [ActionStep, ActionStep, ActionStep, ActionStep];
230
+
231
+ /**
232
+ * Typeguard to determine if a user is supplying a simple or raw EventActionPayload
233
+ *
234
+ * @param {*} opts
235
+ * @returns {opts is EventActionPayloadSimple}
236
+ */
237
+ export function isEventActionPayloadSimple(
238
+ opts: EventActionPayload,
239
+ ): opts is EventActionPayloadSimple {
240
+ return Array.isArray((opts as EventActionPayloadSimple).actionSteps);
241
+ }
242
+
243
+ /**
244
+ * Object representation of an `InitPayload` struct used to initialize event actions.
245
+ *
246
+ * @export
247
+ * @interface EventActionPayloadRaw
248
+ * @typedef {EventActionPayloadRaw}
249
+ */
250
+ export interface EventActionPayloadRaw {
251
+ /**
252
+ * The payload describing how claimants are identified
253
+ *
254
+ * @type {ActionClaimant}
255
+ */
256
+ actionClaimant: ActionClaimant;
257
+ /**
258
+ * The first action step.
259
+ *
260
+ * @type {ActionStep}
261
+ */
262
+ actionStepOne: ActionStep;
263
+ /**
264
+ * The second action step.
265
+ *
266
+ * @type {ActionStep}
267
+ */
268
+ actionStepTwo: ActionStep;
269
+ /**
270
+ * The third action step.
271
+ *
272
+ * @type {ActionStep}
273
+ */
274
+ actionStepThree: ActionStep;
275
+ /**
276
+ * The fourth action step.
277
+ *
278
+ * @type {ActionStep}
279
+ */
280
+ actionStepFour: ActionStep;
281
+ }
282
+
283
+ /**
284
+ * A generic event action
285
+ *
286
+ * @export
287
+ * @class EventAction
288
+ * @typedef {EventAction}
289
+ * @extends {DeployableTarget<EventActionPayload>}
290
+ */
291
+ export class EventAction extends DeployableTarget<
292
+ EventActionPayload,
293
+ typeof eventActionAbi
294
+ > {
295
+ /**
296
+ * @inheritdoc
297
+ *
298
+ * @public
299
+ * @readonly
300
+ * @type {*}
301
+ */
302
+ public override readonly abi = eventActionAbi;
303
+ /**
304
+ * @inheritdoc
305
+ *
306
+ * @public
307
+ * @static
308
+ * @type {Address}
309
+ */
310
+ public static override base: Address = import.meta.env.VITE_EVENT_ACTION_BASE;
311
+ /**
312
+ * @inheritdoc
313
+ *
314
+ * @public
315
+ * @static
316
+ * @type {RegistryType}
317
+ */
318
+ public static override registryType: RegistryType = RegistryType.ACTION;
319
+
320
+ /**
321
+ * Gets a specific action event by index
322
+ *
323
+ * @public
324
+ * @async
325
+ * @param {number} index The index of the action event to retrieve
326
+ * @param {?ReadParams<typeof eventActionAbi, 'getActionStep'>} [params]
327
+ * @returns {Promise<ActionStep>}
328
+ */
329
+ public async getActionStep(
330
+ index: number,
331
+ params?: ReadParams<typeof eventActionAbi, 'getActionStep'>,
332
+ ) {
333
+ const steps = await this.getActionSteps(params);
334
+ return steps.at(index);
335
+ }
336
+
337
+ /**
338
+ * Gets all action events
339
+ *
340
+ * @public
341
+ * @async
342
+ * @param {?ReadParams<typeof eventActionAbi, 'getActionSteps'>} [params]
343
+ * @returns {Promise<ActionStep[]>}
344
+ */
345
+ public async getActionSteps(
346
+ params?: ReadParams<typeof eventActionAbi, 'getActionSteps'>,
347
+ ) {
348
+ const steps = (await readEventActionGetActionSteps(this._config, {
349
+ address: this.assertValidAddress(),
350
+ ...this.optionallyAttachAccount(),
351
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
352
+ ...(params as any),
353
+ })) as RawActionStep[];
354
+ return _dedupeActionSteps(steps.map(_fromRawActionStep));
355
+ }
356
+
357
+ /**
358
+ * Gets the count of action events
359
+ *
360
+ * @public
361
+ * @async
362
+ * @param {?ReadParams<typeof eventActionAbi, 'getActionStepsCount'>} [params]
363
+ * @returns {Promise<bigint>}
364
+ */
365
+ public async getActionStepsCount(
366
+ params?: ReadParams<typeof eventActionAbi, 'getActionStepsCount'>,
367
+ ) {
368
+ const steps = await this.getActionSteps(params);
369
+ return steps.length;
370
+ }
371
+
372
+ /**
373
+ * Retrieves the payload describing how claimants can be identified from logs or function calls.
374
+ *
375
+ * @public
376
+ * @async
377
+ * @param {?ReadParams<typeof eventActionAbi, 'getActionClaimant'>} [params]
378
+ * @returns {Promise<ActionClaimant>}
379
+ */
380
+ public async getActionClaimant(
381
+ params?: ReadParams<typeof eventActionAbi, 'getActionClaimant'>,
382
+ ) {
383
+ const result = (await readEventActionGetActionClaimant(this._config, {
384
+ address: this.assertValidAddress(),
385
+ ...this.optionallyAttachAccount(),
386
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
387
+ ...(params as any),
388
+ })) as RawActionClaimant;
389
+ return _fromRawActionStep(result);
390
+ }
391
+
392
+ /**
393
+ * Executes a prepared event action
394
+ *
395
+ * @public
396
+ * @async
397
+ * @param {Hex} data
398
+ * @param {?WriteParams<typeof eventActionAbi, 'execute'>} [params]
399
+ * @returns {Promise<readonly [boolean, `0x${string}`]>}
400
+ */
401
+ public async execute(
402
+ data: Hex,
403
+ params?: WriteParams<typeof eventActionAbi, 'execute'>,
404
+ ) {
405
+ return await this.awaitResult(this.executeRaw(data, params));
406
+ }
407
+
408
+ /**
409
+ * Executes a prepared event action
410
+ *
411
+ * @public
412
+ * @async
413
+ * @param {Hex} data
414
+ * @param {?WriteParams<typeof eventActionAbi, 'execute'>} [params]
415
+ * @returns {unknown}
416
+ */
417
+ public async executeRaw(
418
+ data: Hex,
419
+ params?: WriteParams<typeof eventActionAbi, 'execute'>,
420
+ ) {
421
+ const { request, result } = await simulateEventActionExecute(this._config, {
422
+ address: this.assertValidAddress(),
423
+ ...this.optionallyAttachAccount(),
424
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
425
+ ...(params as any),
426
+ args: [data],
427
+ });
428
+ const hash = await writeEventActionExecute(this._config, request);
429
+ return { hash, result };
430
+ }
431
+
432
+ /**
433
+ * Retrieves action steps, and uses them to validate against, and optionally fetch logs that match the step's signature.
434
+ * If logs are provided in the optional `params` argument, then those logs will be used instead of fetched with the configured client.
435
+ *
436
+ * @public
437
+ * @async
438
+ * @param {?ReadParams<typeof eventActionAbi, 'getActionSteps'> &
439
+ * GetLogsParams<Abi, ContractEventName<Abi>> & {
440
+ * knownEvents?: Record<Hex, AbiEvent>;
441
+ * logs?: Log[];
442
+ * }} [params]
443
+ * @returns {Promise<boolean>}
444
+ */
445
+ public async validateActionSteps(
446
+ params?: ReadParams<typeof eventActionAbi, 'getActionSteps'> &
447
+ GetLogsParams<Abi, ContractEventName<Abi>> & {
448
+ knownEvents?: Record<Hex, AbiEvent>;
449
+ logs?: Log[];
450
+ },
451
+ ) {
452
+ const actionSteps = await this.getActionSteps(params);
453
+ for (const actionStep of actionSteps) {
454
+ if (!(await this.isActionStepValid(actionStep, params))) {
455
+ return false;
456
+ }
457
+ }
458
+ return true;
459
+ }
460
+
461
+ /**
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.
464
+ *
465
+ * @public
466
+ * @async
467
+ * @param {ActionStep} actionStep
468
+ * @param {?GetLogsParams<Abi, ContractEventName<Abi>> & {
469
+ * knownEvents?: Record<Hex, AbiEvent>;
470
+ * logs?: Log[];
471
+ * }} [params]
472
+ * @returns {Promise<boolean>}
473
+ */
474
+ public async isActionStepValid(
475
+ actionStep: ActionStep,
476
+ params?: GetLogsParams<Abi, ContractEventName<Abi>> & {
477
+ knownEvents?: Record<Hex, AbiEvent>;
478
+ logs?: Log[];
479
+ },
480
+ ) {
481
+ const criteria = actionStep.actionParameter;
482
+ const signature = actionStep.signature;
483
+ let event: AbiEvent;
484
+ // Lookup ABI based on event signature
485
+ if (params?.knownEvents) {
486
+ event = params.knownEvents[signature] as AbiEvent;
487
+ } else {
488
+ event = (events.abi as Record<Hex, AbiEvent>)[signature] as AbiEvent;
489
+ }
490
+ if (!event) {
491
+ throw new Error(`No known ABI for given event signature: ${signature}`);
492
+ }
493
+ const targetContract = actionStep.targetContract;
494
+ // Get all logs matching the event signature from the target contract
495
+ const logs =
496
+ params?.logs ||
497
+ (await getLogs(this._config.getClient({ chainId: params?.chainId }), {
498
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
499
+ ...(params as any),
500
+ address: targetContract,
501
+ event,
502
+ }));
503
+ if (!logs.length) return false;
504
+ for (let log of logs) {
505
+ if (!this.validateLogAgainstCriteria(criteria, log)) {
506
+ return false;
507
+ }
508
+ }
509
+ return true;
510
+ }
511
+
512
+ /**
513
+ * Validates a {@link Log} against a given criteria.
514
+ *
515
+ * @param {Criteria} criteria - The criteria to validate against.
516
+ * @param {Log} log - The Viem event log.
517
+ * @returns {boolean} - Returns true if the log passes the criteria, false otherwise.
518
+ */
519
+ public validateLogAgainstCriteria(criteria: Criteria, log: Log) {
520
+ const fieldValue = log.topics.at(criteria.fieldIndex);
521
+ if (fieldValue === undefined) {
522
+ throw new FieldValueUndefinedError({ log, criteria, fieldValue });
523
+ }
524
+ // Type narrow based on criteria.filterType
525
+ switch (criteria.filterType) {
526
+ case FilterType.EQUAL:
527
+ if (criteria.fieldType === PrimitiveType.ADDRESS) {
528
+ return isAddressEqual(
529
+ criteria.filterData,
530
+ `0x${fieldValue.slice(-40)}`,
531
+ );
532
+ }
533
+ return fieldValue === criteria.filterData;
534
+
535
+ case FilterType.NOT_EQUAL:
536
+ if (criteria.fieldType === PrimitiveType.ADDRESS) {
537
+ return !isAddressEqual(
538
+ criteria.filterData,
539
+ `0x${fieldValue.slice(-40)}`,
540
+ );
541
+ }
542
+ return fieldValue !== criteria.filterData;
543
+
544
+ case FilterType.GREATER_THAN:
545
+ if (criteria.fieldType === PrimitiveType.UINT) {
546
+ return BigInt(fieldValue) > BigInt(criteria.filterData);
547
+ }
548
+ throw new InvalidNumericalCriteriaError({ log, criteria, fieldValue });
549
+
550
+ case FilterType.LESS_THAN:
551
+ if (criteria.fieldType === PrimitiveType.UINT) {
552
+ return BigInt(fieldValue) < BigInt(criteria.filterData);
553
+ }
554
+ throw new InvalidNumericalCriteriaError({ log, criteria, fieldValue });
555
+
556
+ case FilterType.CONTAINS:
557
+ if (
558
+ criteria.fieldType === PrimitiveType.BYTES ||
559
+ criteria.fieldType === PrimitiveType.STRING
560
+ ) {
561
+ return fieldValue.includes(criteria.filterData);
562
+ }
563
+ throw new FieldValueNotComparableError({ log, criteria, fieldValue });
564
+
565
+ default:
566
+ throw new UnrecognizedFilterTypeError({ log, criteria, fieldValue });
567
+ }
568
+ }
569
+
570
+ /**
571
+ * @inheritdoc
572
+ *
573
+ * @public
574
+ * @param {?EventActionPayload} [_payload]
575
+ * @param {?DeployableOptions} [_options]
576
+ * @returns {GenericDeployableParams}
577
+ */
578
+ public override buildParameters(
579
+ _payload?: EventActionPayload,
580
+ _options?: DeployableOptions,
581
+ ): GenericDeployableParams {
582
+ const [payload, options] = this.validateDeploymentConfig(
583
+ _payload,
584
+ _options,
585
+ );
586
+ let rawPayload: EventActionPayloadRaw;
587
+ if (isEventActionPayloadSimple(payload)) {
588
+ // filter out any falsy potential values
589
+ let tmpSteps: ActionStep[] = payload.actionSteps.filter((step) => !!step);
590
+ if (tmpSteps.length === 0) {
591
+ throw new NoEventActionStepsProvidedError();
592
+ }
593
+ if (tmpSteps.length > 4) {
594
+ throw new TooManyEventActionStepsProvidedError();
595
+ }
596
+ let steps: ActionStepTuple = Array.from({ length: 4 }, (_, i) => {
597
+ // use either the provided step at the given index, or reuse the previous step
598
+ // should aways exist
599
+ return tmpSteps.at(i) || tmpSteps.at(-1);
600
+ }) as ActionStepTuple;
601
+ rawPayload = {
602
+ actionClaimant: payload.actionClaimant,
603
+ actionStepOne: steps[0],
604
+ actionStepTwo: steps[1],
605
+ actionStepThree: steps[2],
606
+ actionStepFour: steps[3],
607
+ };
608
+ } else {
609
+ rawPayload = payload;
610
+ }
611
+ return {
612
+ abi: eventActionAbi,
613
+ bytecode: bytecode as Hex,
614
+ args: [prepareEventActionPayload(rawPayload)],
615
+ ...this.optionallyAttachAccount(options.account),
616
+ };
617
+ }
618
+ }
619
+
620
+ function _dedupeActionSteps(_steps: ActionStep[]): ActionStep[] {
621
+ const steps: ActionStep[] = [],
622
+ signatures: Record<string, boolean> = {};
623
+ for (let step of _steps) {
624
+ const signature = JSON.stringify(step);
625
+ if (signatures[signature]) continue;
626
+ steps.push(step);
627
+ signatures[signature] = true;
628
+ }
629
+ return steps;
630
+ }
631
+ type RawActionStep = Overwrite<ActionStep, { chainid: bigint }>;
632
+ type RawActionClaimant = Overwrite<ActionClaimant, { chainid: bigint }>;
633
+
634
+ function _toRawActionStep<T extends ActionStep | ActionClaimant>(obj: T) {
635
+ return {
636
+ ...obj,
637
+ chainid: BigInt(obj.chainid),
638
+ };
639
+ }
640
+
641
+ function _fromRawActionStep<T extends RawActionStep | RawActionClaimant>(
642
+ obj: T,
643
+ ) {
644
+ if (obj.chainid > BigInt(Number.MAX_SAFE_INTEGER)) {
645
+ throw new Error('Chain ID exceeds max safe integer');
646
+ }
647
+
648
+ return {
649
+ ...obj,
650
+ chainid: Number(obj.chainid),
651
+ };
652
+ }
653
+
654
+ /**
655
+ * Typeguard to determine if a user is supplying a simple or raw EventActionPayload
656
+ *
657
+ * @param {*} opts
658
+ * @returns {opts is EventActionPayloadSimple}
659
+ */
660
+ function _isEventActionPayloadSimple(
661
+ opts: EventActionPayload,
662
+ ): opts is EventActionPayloadSimple {
663
+ return Array.isArray((opts as EventActionPayloadSimple).actionSteps);
664
+ }
665
+
666
+ /**
667
+ * Function to properly encode an event action payload.
668
+ *
669
+ * @param {InitPayload} param0
670
+ * @param {ActionStep} param0.actionStepOne - The first action step to initialize.
671
+ * @param {ActionStep} param0.actionStepTwo - The second action step to initialize.
672
+ * @param {ActionStep} param0.actionStepThree - The third action step to initialize.
673
+ * @param {ActionStep} param0.actionStepFour - The fourth action step to initialize.
674
+ * @returns {Hex}
675
+ */
676
+ export function prepareEventActionPayload({
677
+ actionClaimant,
678
+ actionStepOne,
679
+ actionStepTwo,
680
+ actionStepThree,
681
+ actionStepFour,
682
+ }: EventActionPayloadRaw) {
683
+ // note chainIds are technically uint256 but viem treats them (safely) as numbers,
684
+ // so we encode them as uint32 here to avoid downcast issues
685
+ return encodeAbiParameters(
686
+ [
687
+ {
688
+ type: 'tuple',
689
+ name: 'initPayload',
690
+ components: [
691
+ {
692
+ type: 'tuple',
693
+ name: 'actionClaimant',
694
+ components: [
695
+ { type: 'uint8', name: 'signatureType' },
696
+ { type: 'bytes32', name: 'signature' },
697
+ { type: 'uint8', name: 'fieldIndex' },
698
+ { type: 'address', name: 'targetContract' },
699
+ { type: 'uint256', name: 'chainid' },
700
+ ],
701
+ },
702
+ {
703
+ type: 'tuple',
704
+ name: 'actionStepOne',
705
+ components: [
706
+ { type: 'bytes32', name: 'signature' },
707
+ { type: 'uint8', name: 'signatureType' },
708
+ { type: 'uint8', name: 'actionType' },
709
+ { type: 'address', name: 'targetContract' },
710
+ { type: 'uint256', name: 'chainid' },
711
+ {
712
+ type: 'tuple',
713
+ name: 'actionParameter',
714
+ components: [
715
+ { type: 'uint8', name: 'filterType' },
716
+ { type: 'uint8', name: 'fieldType' },
717
+ { type: 'uint8', name: 'fieldIndex' },
718
+ { type: 'bytes', name: 'filterData' },
719
+ ],
720
+ },
721
+ ],
722
+ },
723
+ {
724
+ type: 'tuple',
725
+ name: 'actionStepTwo',
726
+ components: [
727
+ { type: 'bytes32', name: 'signature' },
728
+ { type: 'uint8', name: 'signatureType' },
729
+ { type: 'uint8', name: 'actionType' },
730
+ { type: 'address', name: 'targetContract' },
731
+ { type: 'uint256', name: 'chainid' },
732
+ {
733
+ type: 'tuple',
734
+ name: 'actionParameter',
735
+ components: [
736
+ { type: 'uint8', name: 'filterType' },
737
+ { type: 'uint8', name: 'fieldType' },
738
+ { type: 'uint8', name: 'fieldIndex' },
739
+ { type: 'bytes', name: 'filterData' },
740
+ ],
741
+ },
742
+ ],
743
+ },
744
+ {
745
+ type: 'tuple',
746
+ name: 'actionStepThree',
747
+ components: [
748
+ { type: 'bytes32', name: 'signature' },
749
+ { type: 'uint8', name: 'signatureType' },
750
+ { type: 'uint8', name: 'actionType' },
751
+ { type: 'address', name: 'targetContract' },
752
+ { type: 'uint256', name: 'chainid' },
753
+ {
754
+ type: 'tuple',
755
+ name: 'actionParameter',
756
+ components: [
757
+ { type: 'uint8', name: 'filterType' },
758
+ { type: 'uint8', name: 'fieldType' },
759
+ { type: 'uint8', name: 'fieldIndex' },
760
+ { type: 'bytes', name: 'filterData' },
761
+ ],
762
+ },
763
+ ],
764
+ },
765
+ {
766
+ type: 'tuple',
767
+ name: 'actionStepFour',
768
+ components: [
769
+ { type: 'bytes32', name: 'signature' },
770
+ { type: 'uint8', name: 'signatureType' },
771
+ { type: 'uint8', name: 'actionType' },
772
+ { type: 'address', name: 'targetContract' },
773
+ { type: 'uint256', name: 'chainid' },
774
+ {
775
+ type: 'tuple',
776
+ name: 'actionParameter',
777
+ components: [
778
+ { type: 'uint8', name: 'filterType' },
779
+ { type: 'uint8', name: 'fieldType' },
780
+ { type: 'uint8', name: 'fieldIndex' },
781
+ { type: 'bytes', name: 'filterData' },
782
+ ],
783
+ },
784
+ ],
785
+ },
786
+ ],
787
+ },
788
+ ],
789
+ [
790
+ {
791
+ actionClaimant: _toRawActionStep(actionClaimant),
792
+ actionStepOne: {
793
+ ..._toRawActionStep(actionStepOne),
794
+ actionType: actionStepOne.actionType || 0,
795
+ },
796
+ actionStepTwo: {
797
+ ..._toRawActionStep(actionStepTwo),
798
+ actionType: actionStepTwo.actionType || 0,
799
+ },
800
+ actionStepThree: {
801
+ ..._toRawActionStep(actionStepThree),
802
+ actionType: actionStepThree.actionType || 0,
803
+ },
804
+ actionStepFour: {
805
+ ..._toRawActionStep(actionStepFour),
806
+ actionType: actionStepFour.actionType || 0,
807
+ },
808
+ },
809
+ ],
810
+ );
811
+ }