@boostxyz/sdk 0.0.0-alpha.8 → 0.0.0-alpha.9

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 (180) hide show
  1. package/dist/Actions/Action.cjs +1 -1
  2. package/dist/Actions/Action.js +1 -1
  3. package/dist/Actions/ContractAction.d.ts +46 -3
  4. package/dist/Actions/ContractAction.d.ts.map +1 -1
  5. package/dist/Actions/ERC721MintAction.d.ts +37 -10
  6. package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
  7. package/dist/Actions/EventAction.cjs +1 -1
  8. package/dist/Actions/EventAction.cjs.map +1 -1
  9. package/dist/Actions/EventAction.d.ts +257 -12
  10. package/dist/Actions/EventAction.d.ts.map +1 -1
  11. package/dist/Actions/EventAction.js +249 -82
  12. package/dist/Actions/EventAction.js.map +1 -1
  13. package/dist/AllowLists/AllowList.cjs +1 -1
  14. package/dist/AllowLists/AllowList.js +1 -1
  15. package/dist/AllowLists/SimpleAllowList.cjs +1 -1
  16. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -1
  17. package/dist/AllowLists/SimpleAllowList.d.ts +31 -2
  18. package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
  19. package/dist/AllowLists/SimpleAllowList.js +52 -37
  20. package/dist/AllowLists/SimpleAllowList.js.map +1 -1
  21. package/dist/AllowLists/SimpleDenyList.cjs +1 -1
  22. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -1
  23. package/dist/AllowLists/SimpleDenyList.d.ts +31 -2
  24. package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
  25. package/dist/AllowLists/SimpleDenyList.js +41 -129
  26. package/dist/AllowLists/SimpleDenyList.js.map +1 -1
  27. package/dist/Auth/PassthroughAuth.cjs +1 -1
  28. package/dist/Auth/PassthroughAuth.cjs.map +1 -1
  29. package/dist/Auth/PassthroughAuth.js +4 -4
  30. package/dist/Auth/PassthroughAuth.js.map +1 -1
  31. package/dist/Boost.cjs +1 -1
  32. package/dist/Boost.cjs.map +1 -1
  33. package/dist/Boost.d.ts +93 -1
  34. package/dist/Boost.d.ts.map +1 -1
  35. package/dist/Boost.js +151 -5
  36. package/dist/Boost.js.map +1 -1
  37. package/dist/BoostCore.cjs +2 -2
  38. package/dist/BoostCore.cjs.map +1 -1
  39. package/dist/BoostCore.d.ts +12 -6
  40. package/dist/BoostCore.d.ts.map +1 -1
  41. package/dist/BoostCore.js +168 -166
  42. package/dist/BoostCore.js.map +1 -1
  43. package/dist/BoostRegistry.cjs +1 -1
  44. package/dist/BoostRegistry.cjs.map +1 -1
  45. package/dist/BoostRegistry.d.ts +4 -4
  46. package/dist/BoostRegistry.d.ts.map +1 -1
  47. package/dist/BoostRegistry.js +19 -24
  48. package/dist/BoostRegistry.js.map +1 -1
  49. package/dist/Budgets/Budget.cjs +1 -1
  50. package/dist/Budgets/Budget.js +1 -1
  51. package/dist/Budgets/ManagedBudget.cjs +1 -1
  52. package/dist/Budgets/ManagedBudget.cjs.map +1 -1
  53. package/dist/Budgets/ManagedBudget.d.ts +40 -2
  54. package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
  55. package/dist/Budgets/ManagedBudget.js +53 -36
  56. package/dist/Budgets/ManagedBudget.js.map +1 -1
  57. package/dist/Budgets/SimpleBudget.d.ts +33 -2
  58. package/dist/Budgets/SimpleBudget.d.ts.map +1 -1
  59. package/dist/Budgets/VestingBudget.d.ts +54 -2
  60. package/dist/Budgets/VestingBudget.d.ts.map +1 -1
  61. package/dist/Deployable/Contract.cjs +1 -1
  62. package/dist/Deployable/Contract.cjs.map +1 -1
  63. package/dist/Deployable/Contract.js +1 -1
  64. package/dist/Deployable/Contract.js.map +1 -1
  65. package/dist/Deployable/DeployableTarget.cjs +1 -1
  66. package/dist/Deployable/DeployableTarget.cjs.map +1 -1
  67. package/dist/Deployable/DeployableTarget.js +3 -3
  68. package/dist/Deployable/DeployableTarget.js.map +1 -1
  69. package/dist/Incentives/AllowListIncentive.cjs +1 -1
  70. package/dist/Incentives/AllowListIncentive.cjs.map +1 -1
  71. package/dist/Incentives/AllowListIncentive.d.ts +35 -5
  72. package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
  73. package/dist/Incentives/AllowListIncentive.js +33 -21
  74. package/dist/Incentives/AllowListIncentive.js.map +1 -1
  75. package/dist/Incentives/CGDAIncentive.cjs +1 -1
  76. package/dist/Incentives/CGDAIncentive.cjs.map +1 -1
  77. package/dist/Incentives/CGDAIncentive.d.ts +89 -5
  78. package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
  79. package/dist/Incentives/CGDAIncentive.js +44 -23
  80. package/dist/Incentives/CGDAIncentive.js.map +1 -1
  81. package/dist/Incentives/ERC1155Incentive.d.ts +67 -6
  82. package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
  83. package/dist/Incentives/ERC20Incentive.cjs +1 -1
  84. package/dist/Incentives/ERC20Incentive.cjs.map +1 -1
  85. package/dist/Incentives/ERC20Incentive.d.ts +49 -5
  86. package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
  87. package/dist/Incentives/ERC20Incentive.js +46 -27
  88. package/dist/Incentives/ERC20Incentive.js.map +1 -1
  89. package/dist/Incentives/ERC20VariableIncentive.d.ts +42 -5
  90. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
  91. package/dist/Incentives/Incentive.cjs +1 -1
  92. package/dist/Incentives/Incentive.cjs.map +1 -1
  93. package/dist/Incentives/Incentive.js +48 -32
  94. package/dist/Incentives/Incentive.js.map +1 -1
  95. package/dist/Incentives/PointsIncentive.cjs +1 -1
  96. package/dist/Incentives/PointsIncentive.cjs.map +1 -1
  97. package/dist/Incentives/PointsIncentive.d.ts +49 -5
  98. package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
  99. package/dist/Incentives/PointsIncentive.js +38 -21
  100. package/dist/Incentives/PointsIncentive.js.map +1 -1
  101. package/dist/Validators/SignerValidator.cjs +1 -1
  102. package/dist/Validators/SignerValidator.cjs.map +1 -1
  103. package/dist/Validators/SignerValidator.d.ts +298 -5
  104. package/dist/Validators/SignerValidator.d.ts.map +1 -1
  105. package/dist/Validators/SignerValidator.js +151 -26
  106. package/dist/Validators/SignerValidator.js.map +1 -1
  107. package/dist/Validators/Validator.cjs +1 -1
  108. package/dist/Validators/Validator.js +1 -1
  109. package/dist/claiming.cjs +2 -0
  110. package/dist/claiming.cjs.map +1 -0
  111. package/dist/claiming.d.ts +43 -0
  112. package/dist/claiming.d.ts.map +1 -0
  113. package/dist/claiming.js +17 -0
  114. package/dist/claiming.js.map +1 -0
  115. package/dist/errors.cjs.map +1 -1
  116. package/dist/errors.d.ts +1 -1
  117. package/dist/errors.d.ts.map +1 -1
  118. package/dist/errors.js.map +1 -1
  119. package/dist/{generated-Cbv8zFkf.js → generated-57_Kffpz.js} +8 -5
  120. package/dist/generated-57_Kffpz.js.map +1 -0
  121. package/dist/{generated-BzszviNp.cjs → generated-wKBNvm48.cjs} +2 -2
  122. package/dist/generated-wKBNvm48.cjs.map +1 -0
  123. package/dist/index.cjs +1 -1
  124. package/dist/index.d.ts +4 -4
  125. package/dist/index.d.ts.map +1 -1
  126. package/dist/index.js +108 -125
  127. package/dist/transfers.cjs +2 -0
  128. package/dist/transfers.cjs.map +1 -0
  129. package/dist/transfers.d.ts +198 -0
  130. package/dist/transfers.d.ts.map +1 -0
  131. package/dist/transfers.js +84 -0
  132. package/dist/transfers.js.map +1 -0
  133. package/dist/utils.cjs +1 -1
  134. package/dist/utils.cjs.map +1 -1
  135. package/dist/utils.d.ts +2 -1371
  136. package/dist/utils.d.ts.map +1 -1
  137. package/dist/utils.js +26 -653
  138. package/dist/utils.js.map +1 -1
  139. package/package.json +17 -3
  140. package/src/Actions/Action.test.ts +5 -4
  141. package/src/Actions/ContractAction.test.ts +4 -6
  142. package/src/Actions/ContractAction.ts +73 -10
  143. package/src/Actions/ERC721MintAction.test.ts +2 -2
  144. package/src/Actions/ERC721MintAction.ts +70 -16
  145. package/src/Actions/EventAction.test.ts +43 -17
  146. package/src/Actions/EventAction.ts +452 -35
  147. package/src/AllowLists/SimpleAllowList.ts +48 -5
  148. package/src/AllowLists/SimpleDenyList.ts +47 -109
  149. package/src/Auth/PassthroughAuth.ts +1 -1
  150. package/src/Boost.ts +136 -1
  151. package/src/BoostCore.test.ts +4 -11
  152. package/src/BoostCore.ts +39 -33
  153. package/src/BoostRegistry.ts +19 -22
  154. package/src/Budgets/ManagedBudget.ts +69 -16
  155. package/src/Budgets/SimpleBudget.ts +57 -14
  156. package/src/Budgets/VestingBudget.ts +79 -9
  157. package/src/Deployable/Contract.ts +1 -1
  158. package/src/Deployable/DeployableTarget.ts +2 -2
  159. package/src/Incentives/AllowListIncentive.test.ts +2 -5
  160. package/src/Incentives/AllowListIncentive.ts +59 -15
  161. package/src/Incentives/CGDAIncentive.test.ts +3 -7
  162. package/src/Incentives/CGDAIncentive.ts +123 -19
  163. package/src/Incentives/ERC1155Incentive.test.ts +2 -13
  164. package/src/Incentives/ERC1155Incentive.ts +104 -22
  165. package/src/Incentives/ERC20Incentive.test.ts +6 -17
  166. package/src/Incentives/ERC20Incentive.ts +86 -21
  167. package/src/Incentives/ERC20VariableIncentive.test.ts +4 -24
  168. package/src/Incentives/ERC20VariableIncentive.ts +71 -19
  169. package/src/Incentives/Incentive.test.ts +1 -1
  170. package/src/Incentives/PointsIncentive.test.ts +3 -6
  171. package/src/Incentives/PointsIncentive.ts +79 -17
  172. package/src/Validators/SignerValidator.test.ts +3 -7
  173. package/src/Validators/SignerValidator.ts +422 -13
  174. package/src/claiming.ts +56 -0
  175. package/src/errors.ts +1 -1
  176. package/src/index.ts +10 -7
  177. package/src/transfers.ts +284 -0
  178. package/src/utils.ts +3 -2052
  179. package/dist/generated-BzszviNp.cjs.map +0 -1
  180. package/dist/generated-Cbv8zFkf.js.map +0 -1
@@ -14,6 +14,7 @@ import {
14
14
  type ContractEventName,
15
15
  type Hex,
16
16
  type Log,
17
+ encodeAbiParameters,
17
18
  isAddressEqual,
18
19
  } from 'viem';
19
20
  import { getLogs } from 'viem/actions';
@@ -31,31 +32,253 @@ import {
31
32
  UnrecognizedFilterTypeError,
32
33
  } from '../errors';
33
34
  import {
34
- type ActionClaimant,
35
- type ActionStep,
36
- type Criteria,
37
- type EventActionPayload,
38
- type EventActionPayloadRaw,
39
- FilterType,
40
35
  type GetLogsParams,
41
- PrimitiveType,
36
+ type Overwrite,
42
37
  type ReadParams,
43
38
  RegistryType,
44
39
  type WriteParams,
45
- dedupeActionSteps,
46
- isEventActionPayloadSimple,
47
- prepareEventActionPayload,
48
40
  } from '../utils';
49
- import type { SignatureType } from './../utils';
50
41
 
51
- export type {
52
- EventActionPayload,
53
- ActionStep,
54
- ActionClaimant,
55
- SignatureType,
56
- FilterType,
57
- PrimitiveType,
58
- };
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
+ }
59
282
 
60
283
  /**
61
284
  * A generic event action
@@ -127,8 +350,8 @@ export class EventAction extends DeployableTarget<
127
350
  ...this.optionallyAttachAccount(),
128
351
  // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
129
352
  ...(params as any),
130
- })) as ActionStep[];
131
- return dedupeActionSteps(steps);
353
+ })) as RawActionStep[];
354
+ return _dedupeActionSteps(steps.map(_fromRawActionStep));
132
355
  }
133
356
 
134
357
  /**
@@ -157,12 +380,13 @@ export class EventAction extends DeployableTarget<
157
380
  public async getActionClaimant(
158
381
  params?: ReadParams<typeof eventActionAbi, 'getActionClaimant'>,
159
382
  ) {
160
- return readEventActionGetActionClaimant(this._config, {
383
+ const result = (await readEventActionGetActionClaimant(this._config, {
161
384
  address: this.assertValidAddress(),
162
385
  ...this.optionallyAttachAccount(),
163
386
  // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
164
387
  ...(params as any),
165
- }) as Promise<ActionClaimant>;
388
+ })) as RawActionClaimant;
389
+ return _fromRawActionStep(result);
166
390
  }
167
391
 
168
392
  /**
@@ -178,7 +402,7 @@ export class EventAction extends DeployableTarget<
178
402
  data: Hex,
179
403
  params?: WriteParams<typeof eventActionAbi, 'execute'>,
180
404
  ) {
181
- return this.awaitResult(this.executeRaw(data, params));
405
+ return await this.awaitResult(this.executeRaw(data, params));
182
406
  }
183
407
 
184
408
  /**
@@ -278,7 +502,7 @@ export class EventAction extends DeployableTarget<
278
502
  }));
279
503
  if (!logs.length) return false;
280
504
  for (let log of logs) {
281
- if (!(await this.validateLogAgainstCriteria(criteria, log))) {
505
+ if (!this.validateLogAgainstCriteria(criteria, log)) {
282
506
  return false;
283
507
  }
284
508
  }
@@ -290,9 +514,9 @@ export class EventAction extends DeployableTarget<
290
514
  *
291
515
  * @param {Criteria} criteria - The criteria to validate against.
292
516
  * @param {Log} log - The Viem event log.
293
- * @returns {Promise<boolean>} - Returns true if the log passes the criteria, false otherwise.
517
+ * @returns {boolean} - Returns true if the log passes the criteria, false otherwise.
294
518
  */
295
- public async validateLogAgainstCriteria(criteria: Criteria, log: Log) {
519
+ public validateLogAgainstCriteria(criteria: Criteria, log: Log) {
296
520
  const fieldValue = log.topics.at(criteria.fieldIndex);
297
521
  if (fieldValue === undefined) {
298
522
  throw new FieldValueUndefinedError({ log, criteria, fieldValue });
@@ -356,24 +580,24 @@ export class EventAction extends DeployableTarget<
356
580
  let rawPayload: EventActionPayloadRaw;
357
581
  if (isEventActionPayloadSimple(payload)) {
358
582
  // filter out any falsy potential values
359
- let tmpSteps = payload.actionSteps.filter((step) => !!step);
583
+ let tmpSteps: ActionStep[] = payload.actionSteps.filter((step) => !!step);
360
584
  if (tmpSteps.length === 0) {
361
585
  throw new NoEventActionStepsProvidedError();
362
586
  }
363
587
  if (tmpSteps.length > 4) {
364
588
  throw new TooManyEventActionStepsProvidedError();
365
589
  }
366
- let steps: ActionStep[] = Array.from({ length: 4 }, (_, i) => {
590
+ let steps: ActionStepTuple = Array.from({ length: 4 }, (_, i) => {
367
591
  // use either the provided step at the given index, or reuse the previous step
368
592
  // should aways exist
369
- return tmpSteps.at(i)! || tmpSteps.slice(0, i).at(-1)!;
370
- });
593
+ return tmpSteps.at(i) || tmpSteps.at(-1);
594
+ }) as ActionStepTuple;
371
595
  rawPayload = {
372
596
  actionClaimant: payload.actionClaimant,
373
- actionStepOne: steps.at(0)!,
374
- actionStepTwo: steps.at(1)!,
375
- actionStepThree: steps.at(2)!,
376
- actionStepFour: steps.at(3)!,
597
+ actionStepOne: steps[0],
598
+ actionStepTwo: steps[1],
599
+ actionStepThree: steps[2],
600
+ actionStepFour: steps[3],
377
601
  };
378
602
  } else {
379
603
  rawPayload = payload;
@@ -386,3 +610,196 @@ export class EventAction extends DeployableTarget<
386
610
  };
387
611
  }
388
612
  }
613
+
614
+ function _dedupeActionSteps(_steps: ActionStep[]): ActionStep[] {
615
+ const steps: ActionStep[] = [],
616
+ signatures: Record<string, boolean> = {};
617
+ for (let step of _steps) {
618
+ const signature = JSON.stringify(step);
619
+ if (signatures[signature]) continue;
620
+ steps.push(step);
621
+ signatures[signature] = true;
622
+ }
623
+ return steps;
624
+ }
625
+ type RawActionStep = Overwrite<ActionStep, { chainid: bigint }>;
626
+ type RawActionClaimant = Overwrite<ActionClaimant, { chainid: bigint }>;
627
+
628
+ function _toRawActionStep<T extends ActionStep | ActionClaimant>(obj: T) {
629
+ return {
630
+ ...obj,
631
+ chainid: BigInt(obj.chainid),
632
+ };
633
+ }
634
+
635
+ function _fromRawActionStep<T extends RawActionStep | RawActionClaimant>(
636
+ obj: T,
637
+ ) {
638
+ if (obj.chainid > BigInt(Number.MAX_SAFE_INTEGER)) {
639
+ throw new Error('Chain ID exceeds max safe integer');
640
+ }
641
+
642
+ return {
643
+ ...obj,
644
+ chainid: Number(obj.chainid),
645
+ };
646
+ }
647
+
648
+ /**
649
+ * Typeguard to determine if a user is supplying a simple or raw EventActionPayload
650
+ *
651
+ * @param {*} opts
652
+ * @returns {opts is EventActionPayloadSimple}
653
+ */
654
+ function _isEventActionPayloadSimple(
655
+ opts: EventActionPayload,
656
+ ): opts is EventActionPayloadSimple {
657
+ return Array.isArray((opts as EventActionPayloadSimple).actionSteps);
658
+ }
659
+
660
+ /**
661
+ * Function to properly encode an event action payload.
662
+ *
663
+ * @param {InitPayload} param0
664
+ * @param {ActionStep} param0.actionStepOne - The first action step to initialize.
665
+ * @param {ActionStep} param0.actionStepTwo - The second action step to initialize.
666
+ * @param {ActionStep} param0.actionStepThree - The third action step to initialize.
667
+ * @param {ActionStep} param0.actionStepFour - The fourth action step to initialize.
668
+ * @returns {Hex}
669
+ */
670
+ export function prepareEventActionPayload({
671
+ actionClaimant,
672
+ actionStepOne,
673
+ actionStepTwo,
674
+ actionStepThree,
675
+ actionStepFour,
676
+ }: EventActionPayloadRaw) {
677
+ // note chainIds are technically uint256 but viem treats them (safely) as numbers,
678
+ // so we encode them as uint32 here to avoid downcast issues
679
+ return encodeAbiParameters(
680
+ [
681
+ {
682
+ type: 'tuple',
683
+ name: 'initPayload',
684
+ components: [
685
+ {
686
+ type: 'tuple',
687
+ name: 'actionClaimant',
688
+ components: [
689
+ { type: 'uint8', name: 'signatureType' },
690
+ { type: 'bytes32', name: 'signature' },
691
+ { type: 'uint8', name: 'fieldIndex' },
692
+ { type: 'address', name: 'targetContract' },
693
+ { type: 'uint256', name: 'chainid' },
694
+ ],
695
+ },
696
+ {
697
+ type: 'tuple',
698
+ name: 'actionStepOne',
699
+ components: [
700
+ { type: 'bytes32', name: 'signature' },
701
+ { type: 'uint8', name: 'signatureType' },
702
+ { type: 'uint8', name: 'actionType' },
703
+ { type: 'address', name: 'targetContract' },
704
+ { type: 'uint256', name: 'chainid' },
705
+ {
706
+ type: 'tuple',
707
+ name: 'actionParameter',
708
+ components: [
709
+ { type: 'uint8', name: 'filterType' },
710
+ { type: 'uint8', name: 'fieldType' },
711
+ { type: 'uint8', name: 'fieldIndex' },
712
+ { type: 'bytes', name: 'filterData' },
713
+ ],
714
+ },
715
+ ],
716
+ },
717
+ {
718
+ type: 'tuple',
719
+ name: 'actionStepTwo',
720
+ components: [
721
+ { type: 'bytes32', name: 'signature' },
722
+ { type: 'uint8', name: 'signatureType' },
723
+ { type: 'uint8', name: 'actionType' },
724
+ { type: 'address', name: 'targetContract' },
725
+ { type: 'uint256', name: 'chainid' },
726
+ {
727
+ type: 'tuple',
728
+ name: 'actionParameter',
729
+ components: [
730
+ { type: 'uint8', name: 'filterType' },
731
+ { type: 'uint8', name: 'fieldType' },
732
+ { type: 'uint8', name: 'fieldIndex' },
733
+ { type: 'bytes', name: 'filterData' },
734
+ ],
735
+ },
736
+ ],
737
+ },
738
+ {
739
+ type: 'tuple',
740
+ name: 'actionStepThree',
741
+ components: [
742
+ { type: 'bytes32', name: 'signature' },
743
+ { type: 'uint8', name: 'signatureType' },
744
+ { type: 'uint8', name: 'actionType' },
745
+ { type: 'address', name: 'targetContract' },
746
+ { type: 'uint256', name: 'chainid' },
747
+ {
748
+ type: 'tuple',
749
+ name: 'actionParameter',
750
+ components: [
751
+ { type: 'uint8', name: 'filterType' },
752
+ { type: 'uint8', name: 'fieldType' },
753
+ { type: 'uint8', name: 'fieldIndex' },
754
+ { type: 'bytes', name: 'filterData' },
755
+ ],
756
+ },
757
+ ],
758
+ },
759
+ {
760
+ type: 'tuple',
761
+ name: 'actionStepFour',
762
+ components: [
763
+ { type: 'bytes32', name: 'signature' },
764
+ { type: 'uint8', name: 'signatureType' },
765
+ { type: 'uint8', name: 'actionType' },
766
+ { type: 'address', name: 'targetContract' },
767
+ { type: 'uint256', name: 'chainid' },
768
+ {
769
+ type: 'tuple',
770
+ name: 'actionParameter',
771
+ components: [
772
+ { type: 'uint8', name: 'filterType' },
773
+ { type: 'uint8', name: 'fieldType' },
774
+ { type: 'uint8', name: 'fieldIndex' },
775
+ { type: 'bytes', name: 'filterData' },
776
+ ],
777
+ },
778
+ ],
779
+ },
780
+ ],
781
+ },
782
+ ],
783
+ [
784
+ {
785
+ actionClaimant: _toRawActionStep(actionClaimant),
786
+ actionStepOne: {
787
+ ..._toRawActionStep(actionStepOne),
788
+ actionType: actionStepOne.actionType || 0,
789
+ },
790
+ actionStepTwo: {
791
+ ..._toRawActionStep(actionStepTwo),
792
+ actionType: actionStepTwo.actionType || 0,
793
+ },
794
+ actionStepThree: {
795
+ ..._toRawActionStep(actionStepThree),
796
+ actionType: actionStepThree.actionType || 0,
797
+ },
798
+ actionStepFour: {
799
+ ..._toRawActionStep(actionStepFour),
800
+ actionType: actionStepFour.actionType || 0,
801
+ },
802
+ },
803
+ ],
804
+ );
805
+ }
@@ -12,6 +12,7 @@ import {
12
12
  type Address,
13
13
  type ContractEventName,
14
14
  type Hex,
15
+ encodeAbiParameters,
15
16
  zeroAddress,
16
17
  zeroHash,
17
18
  } from 'viem';
@@ -25,13 +26,32 @@ import {
25
26
  type GenericLog,
26
27
  type ReadParams,
27
28
  RegistryType,
28
- type SimpleAllowListPayload,
29
29
  type WriteParams,
30
- prepareSimpleAllowListPayload,
31
30
  } from '../utils';
32
31
 
33
32
  export { simpleAllowListAbi };
34
- export type { SimpleAllowListPayload };
33
+
34
+ /**
35
+ * Object representation of a {@link SimpleAllowList} initialization payload.
36
+ *
37
+ * @export
38
+ * @interface SimpleAllowListPayload
39
+ * @typedef {SimpleAllowListPayload}
40
+ */
41
+ export interface SimpleAllowListPayload {
42
+ /**
43
+ * The allow list's owner, given the {@link LIST_MANAGER_ROLE} role.
44
+ *
45
+ * @type {Address}
46
+ */
47
+ owner: Address;
48
+ /**
49
+ * List of allowed addresses.
50
+ *
51
+ * @type {Address[]}
52
+ */
53
+ allowed: Address[];
54
+ }
35
55
 
36
56
  /**
37
57
  * A generic `viem.Log` event with support for `SimpleAllowList` event types.
@@ -123,7 +143,9 @@ export class SimpleAllowList extends DeployableTarget<
123
143
  allowed: boolean[],
124
144
  params?: WriteParams<typeof simpleAllowListAbi, 'setAllowed'>,
125
145
  ) {
126
- return this.awaitResult(this.setAllowedRaw(addresses, allowed, params));
146
+ return await this.awaitResult(
147
+ this.setAllowedRaw(addresses, allowed, params),
148
+ );
127
149
  }
128
150
 
129
151
  /**
@@ -171,7 +193,7 @@ export class SimpleAllowList extends DeployableTarget<
171
193
  role: bigint,
172
194
  params?: WriteParams<typeof simpleAllowListAbi, 'grantRoles'>,
173
195
  ) {
174
- return this.awaitResult(this.grantRolesRaw(address, role, params));
196
+ return await this.awaitResult(this.grantRolesRaw(address, role, params));
175
197
  }
176
198
 
177
199
  /**
@@ -239,3 +261,24 @@ export class SimpleAllowList extends DeployableTarget<
239
261
  };
240
262
  }
241
263
  }
264
+
265
+ /**
266
+ * Given a {@link SimpleAllowListPayload}, properly encode the initialization payload.
267
+ *
268
+ * @param {SimpleAllowListPayload} param0
269
+ * @param {Address} param0.owner - The allow list's owner, given the {@link LIST_MANAGER_ROLE} role.
270
+ * @param {Address[]} param0.allowed - List of allowed addresses.
271
+ * @returns {Hex}
272
+ */
273
+ export function prepareSimpleAllowListPayload({
274
+ owner,
275
+ allowed,
276
+ }: SimpleAllowListPayload) {
277
+ return encodeAbiParameters(
278
+ [
279
+ { type: 'address', name: 'owner' },
280
+ { type: 'address[]', name: 'allowed' },
281
+ ],
282
+ [owner, allowed],
283
+ );
284
+ }