@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,681 @@
1
+ import {
2
+ readSignerValidatorHashSignerData,
3
+ readSignerValidatorSigners,
4
+ signerValidatorAbi,
5
+ simulateSignerValidatorSetAuthorized,
6
+ simulateSignerValidatorSetValidatorCaller,
7
+ simulateSignerValidatorValidate,
8
+ writeSignerValidatorSetAuthorized,
9
+ writeSignerValidatorSetValidatorCaller,
10
+ writeSignerValidatorValidate,
11
+ } from '@boostxyz/evm';
12
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/validators/SignerValidator.sol/SignerValidator.json';
13
+ import {
14
+ type Address,
15
+ type ContractEventName,
16
+ type Hex,
17
+ type PrivateKeyAccount,
18
+ encodeAbiParameters,
19
+ } from 'viem';
20
+ import { signTypedData } from 'viem/accounts';
21
+ import type {
22
+ DeployableOptions,
23
+ GenericDeployableParams,
24
+ } from '../Deployable/Deployable';
25
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
26
+ import {
27
+ type GenericLog,
28
+ type ReadParams,
29
+ RegistryType,
30
+ type WriteParams,
31
+ } from '../utils';
32
+
33
+ export { signerValidatorAbi };
34
+
35
+ /**
36
+ * Object reprentation of a {@link SignerValidator} initialization payload
37
+ *
38
+ * @export
39
+ * @interface SignerValidatorPayload
40
+ * @typedef {SignerValidatorPayload}
41
+ */
42
+ export interface SignerValidatorPayload {
43
+ /**
44
+ * The list of authorized signers. The first address in the list will be the initial owner of the contract.
45
+ *
46
+ * @type {Address[]}
47
+ */
48
+ signers: Address[];
49
+ /**
50
+ * The authorized caller of the {@link prepareSignerValidator} function
51
+ * @type {Address}
52
+ */
53
+ validatorCaller: Address;
54
+ }
55
+
56
+ /**
57
+ * Description placeholder
58
+ *
59
+ * @export
60
+ * @interface SignerValidatorValidatePayload
61
+ * @typedef {SignerValidatorValidatePayload}
62
+ */
63
+ export interface SignerValidatorValidatePayload {
64
+ /**
65
+ * The ID of the boost.
66
+ *
67
+ * @type {bigint}
68
+ */
69
+ boostId: bigint;
70
+ /**
71
+ * The ID of the incentive.
72
+ *
73
+ * @type {bigint}
74
+ */
75
+ incentiveId: bigint;
76
+ /**
77
+ * The address of the claimant.
78
+ *
79
+ * @type {Address}
80
+ */
81
+ claimant: Address;
82
+ /**
83
+ * The claim data.
84
+ *
85
+ * @type {Hex}
86
+ */
87
+ claimData: Hex;
88
+ }
89
+
90
+ /**
91
+ * Object reprentation of a {@link SignerValidator} initialization payload
92
+ *
93
+ * @export
94
+ * @interface SignerValidatorPayload
95
+ * @typedef {SignerValidatorPayload}
96
+ */
97
+ export interface SignerValidatorPayload {
98
+ /**
99
+ * The list of authorized signers. The first address in the list will be the initial owner of the contract.
100
+ *
101
+ * @type {Address[]}
102
+ */
103
+ signers: Address[];
104
+ /**
105
+ * The authorized caller of the {@link prepareSignerValidator} function
106
+ * @type {Address}
107
+ */
108
+ validatorCaller: Address;
109
+ }
110
+
111
+ /**
112
+ * Description placeholder
113
+ *
114
+ * @export
115
+ * @interface SignerValidatorValidatePayload
116
+ * @typedef {SignerValidatorValidatePayload}
117
+ */
118
+ export interface SignerValidatorValidatePayload {
119
+ /**
120
+ * The ID of the boost.
121
+ *
122
+ * @type {bigint}
123
+ */
124
+ boostId: bigint;
125
+ /**
126
+ * The ID of the incentive.
127
+ *
128
+ * @type {bigint}
129
+ */
130
+ incentiveId: bigint;
131
+ /**
132
+ * The address of the claimant.
133
+ *
134
+ * @type {Address}
135
+ */
136
+ claimant: Address;
137
+ /**
138
+ * The claim data.
139
+ *
140
+ * @type {Hex}
141
+ */
142
+ claimData: Hex;
143
+ }
144
+
145
+ /**
146
+ * Signer Validator Claim Data Payload
147
+ *
148
+ * @export
149
+ * @interface SignerValidatorClaimDataParams
150
+ * @typedef {SignerValidatorClaimDataParams}
151
+ */
152
+ export interface SignerValidatorClaimDataParams {
153
+ /**
154
+ * The signer with which to sign the input
155
+ *
156
+ * @type {{
157
+ * account: Address;
158
+ * key: Hex;
159
+ * privateKey: PrivateKeyAccount;
160
+ * }}
161
+ */
162
+ signer: {
163
+ account: Address;
164
+ key: Hex;
165
+ privateKey: PrivateKeyAccount;
166
+ };
167
+ /**
168
+ * The encoded data to provide the underlying incentive. You can use {@link prepareAllowListIncentivePayload}, {@link prepareCGDAIncentivePayload}, {@link prepareERC20IncentivePayload}, {@link prepareERC1155IncentivePayload}, or {@link preparePointsIncentivePayload}
169
+ *
170
+ * @type {Hex}
171
+ */
172
+ incentiveData: Hex;
173
+ /**
174
+ * The chain id to target
175
+ *
176
+ * @type {number}
177
+ */
178
+ chainId: number;
179
+ /**
180
+ * The address of the validator
181
+ *
182
+ * @type {Address}
183
+ */
184
+ validator: Address;
185
+ /**
186
+ * The incentive quantity.
187
+ *
188
+ * @type {number}
189
+ */
190
+ incentiveQuantity: number;
191
+ /**
192
+ * The address of the claimant
193
+ *
194
+ * @type {Address}
195
+ */
196
+ claimant: Address;
197
+ /**
198
+ * The ID of the boost
199
+ *
200
+ * @type {bigint}
201
+ */
202
+ boostId: bigint;
203
+ }
204
+
205
+ /**
206
+ * Object representation of a {@link SignerValidatorInputParams} initialization payload
207
+ *
208
+ * @export
209
+ * @interface SignerValidatorInputParams
210
+ * @typedef {SignerValidatorInputParams}
211
+ */
212
+ export interface SignerValidatorInputParams {
213
+ /**
214
+ * The signer address.
215
+ *
216
+ * @type {Address}
217
+ */
218
+ signer: Address;
219
+
220
+ /**
221
+ * The signature data.
222
+ *
223
+ * @type {string}
224
+ */
225
+ signature: Hex;
226
+
227
+ /**
228
+ * The incentive quantity.
229
+ *
230
+ * @type {number}
231
+ */
232
+ incentiveQuantity: number;
233
+ }
234
+
235
+ /**
236
+ * Object representing the payload for signing before validaton.
237
+ *
238
+ * @export
239
+ * @interface SignerValidatorSignaturePayload
240
+ * @typedef {SignerValidatorSignaturePayload}
241
+ */
242
+ export interface SignerValidatorSignaturePayload {
243
+ /**
244
+ * The ID of the boost.
245
+ *
246
+ * @type {bigint}
247
+ */
248
+ boostId: bigint;
249
+ /**
250
+ * The ID of the incentive.
251
+ *
252
+ * @type {number}
253
+ */
254
+ incentiveQuantity: number;
255
+ /**
256
+ * The address of the claimant.
257
+ *
258
+ * @type {Address}
259
+ */
260
+ claimant: Address;
261
+ /**
262
+ * The claim data.
263
+ *
264
+ * @type {Hex}
265
+ */
266
+ incentiveData: Hex;
267
+ }
268
+
269
+ /**
270
+ * A generic `viem.Log` event with support for `BoostCore` event types.
271
+ *
272
+ * @export
273
+ * @typedef {SignerValidatorLog}
274
+ * @template {ContractEventName<
275
+ * typeof signerValidatorAbi
276
+ * >} [event=ContractEventName<typeof signerValidatorAbi>]
277
+ */
278
+ export type SignerValidatorLog<
279
+ event extends ContractEventName<
280
+ typeof signerValidatorAbi
281
+ > = ContractEventName<typeof signerValidatorAbi>,
282
+ > = GenericLog<typeof signerValidatorAbi, event>;
283
+
284
+ /**
285
+ * A simple implementation of a Validator that verifies a given signature and checks the recovered address against a set of authorized signers
286
+ *
287
+ * @export
288
+ * @class SignerValidator
289
+ * @typedef {SignerValidator}
290
+ * @extends {DeployableTarget<SignerValidatorPayload>}
291
+ */
292
+ export class SignerValidator extends DeployableTarget<
293
+ SignerValidatorPayload,
294
+ typeof signerValidatorAbi
295
+ > {
296
+ /**
297
+ * @inheritdoc
298
+ *
299
+ * @public
300
+ * @readonly
301
+ * @type {*}
302
+ */
303
+ public override readonly abi = signerValidatorAbi;
304
+ /**
305
+ * @inheritdoc
306
+ *
307
+ * @public
308
+ * @static
309
+ * @type {Address}
310
+ */
311
+ public static override base: Address = import.meta.env
312
+ .VITE_SIGNER_VALIDATOR_BASE;
313
+ /**
314
+ * @inheritdoc
315
+ *
316
+ * @public
317
+ * @static
318
+ * @type {RegistryType}
319
+ */
320
+ public static override registryType: RegistryType = RegistryType.VALIDATOR;
321
+
322
+ /**
323
+ * The set of authorized signers
324
+ *
325
+ * @public
326
+ * @async
327
+ * @param {Address} address
328
+ * @param {?ReadParams<typeof signerValidatorAbi, 'signers'>} [params]
329
+ * @returns {unknown}
330
+ */
331
+ public async signers(
332
+ address: Address,
333
+ params?: ReadParams<typeof signerValidatorAbi, 'signers'>,
334
+ ) {
335
+ return await readSignerValidatorSigners(this._config, {
336
+ address: this.assertValidAddress(),
337
+ args: [address],
338
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
339
+ ...(params as any),
340
+ });
341
+ }
342
+
343
+ /**
344
+ * Retrieve the hash and signer data for a given hash
345
+ *
346
+ * @public
347
+ * @async
348
+ * @param {SignerValidatorSignaturePayload} payload
349
+ * @param {?ReadParams<typeof signerValidatorAbi, 'hashSignerData'>} [params]
350
+ * @returns {unknown}
351
+ */
352
+ public async hashSignerData(
353
+ payload: SignerValidatorSignaturePayload,
354
+ params?: ReadParams<typeof signerValidatorAbi, 'hashSignerData'>,
355
+ ) {
356
+ return await readSignerValidatorHashSignerData(this._config, {
357
+ address: this.assertValidAddress(),
358
+ args: [
359
+ payload.boostId,
360
+ payload.incentiveQuantity,
361
+ payload.claimant,
362
+ payload.incentiveData,
363
+ ],
364
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
365
+ ...(params as any),
366
+ });
367
+ }
368
+
369
+ /**
370
+ * Validate that the action has been completed successfully. The data payload is expected to be a tuple of (address signer, bytes32 hash, bytes signature). The signature is expected to be a valid ECDSA or EIP-1271 signature of a unique hash by an authorized signer.
371
+ *
372
+ * @public
373
+ * @async
374
+ * @param {SignerValidatorValidatePayload} payload
375
+ * @param {?WriteParams<typeof signerValidatorAbi, 'validate'>} [params]
376
+ * @returns {Promise<boolean>} - True if the action has been validated based on the data payload
377
+ */
378
+ protected async validate(
379
+ payload: SignerValidatorValidatePayload,
380
+ params?: WriteParams<typeof signerValidatorAbi, 'validate'>,
381
+ ) {
382
+ return await this.awaitResult(this.validateRaw(payload, params));
383
+ }
384
+
385
+ /**
386
+ * Validate that the action has been completed successfully. The data payload is expected to be a tuple of (address signer, bytes32 hash, bytes signature). The signature is expected to be a valid ECDSA or EIP-1271 signature of a unique hash by an authorized signer.
387
+ *
388
+ * @public
389
+ * @async
390
+ * @param {SignerValidatorValidatePayload} payload
391
+ * @param {?WriteParams<typeof signerValidatorAbi, 'validate'>} [params]
392
+ * @returns {Promise<boolean>} - True if the action has been validated based on the data payload
393
+ */
394
+ protected async validateRaw(
395
+ payload: SignerValidatorValidatePayload,
396
+ params?: ReadParams<typeof signerValidatorAbi, 'validate'>,
397
+ ) {
398
+ const { request, result } = await simulateSignerValidatorValidate(
399
+ this._config,
400
+ {
401
+ address: this.assertValidAddress(),
402
+ args: [
403
+ payload.boostId,
404
+ payload.incentiveId,
405
+ payload.claimant,
406
+ payload.claimData,
407
+ ],
408
+ ...this.optionallyAttachAccount(),
409
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
410
+ ...(params as any),
411
+ },
412
+ );
413
+ const hash = await writeSignerValidatorValidate(this._config, request);
414
+ return { hash, result };
415
+ }
416
+
417
+ /**
418
+ * Set the authorized status of a signer
419
+ *
420
+ * @public
421
+ * @async
422
+ * @param {Address[]} addresses - The list of signers to update
423
+ * @param {boolean[]} allowed - The authorized status of each signer
424
+ * @param {?WriteParams<typeof signerValidatorAbi, 'setAuthorized'>} [params]
425
+ * @returns {unknown}
426
+ */
427
+ public async setAuthorized(
428
+ addresses: Address[],
429
+ allowed: boolean[],
430
+ params?: WriteParams<typeof signerValidatorAbi, 'setAuthorized'>,
431
+ ) {
432
+ return await this.awaitResult(
433
+ this.setAuthorizedRaw(addresses, allowed, params),
434
+ );
435
+ }
436
+
437
+ /**
438
+ * Set the authorized status of a signer
439
+ *
440
+ * @public
441
+ * @async
442
+ * @param {Address[]} addresses - The list of signers to update
443
+ * @param {boolean[]} allowed - The authorized status of each signer
444
+ * @param {?WriteParams<typeof signerValidatorAbi, 'setAuthorized'>} [params]
445
+ * @returns {unknown}
446
+ */
447
+ public async setAuthorizedRaw(
448
+ addresses: Address[],
449
+ allowed: boolean[],
450
+ params?: WriteParams<typeof signerValidatorAbi, 'setAuthorized'>,
451
+ ) {
452
+ const { request, result } = await simulateSignerValidatorSetAuthorized(
453
+ this._config,
454
+ {
455
+ address: this.assertValidAddress(),
456
+ args: [addresses, allowed],
457
+ ...this.optionallyAttachAccount(),
458
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
459
+ ...(params as any),
460
+ },
461
+ );
462
+ const hash = await writeSignerValidatorSetAuthorized(this._config, request);
463
+ return { hash, result };
464
+ }
465
+
466
+ /**
467
+ * Update the authorized caller of the validator function
468
+ *
469
+ * @public
470
+ * @async
471
+ * @param {Address} address
472
+ * @param {?WriteParams<typeof signerValidatorAbi, 'setValidatorCaller'>} [params]
473
+ * @returns {unknown}
474
+ */
475
+ public async setValidatorCallerRaw(
476
+ address: Address,
477
+ params?: WriteParams<typeof signerValidatorAbi, 'setValidatorCaller'>,
478
+ ) {
479
+ const { request, result } = await simulateSignerValidatorSetValidatorCaller(
480
+ this._config,
481
+ {
482
+ address: this.assertValidAddress(),
483
+ args: [address],
484
+ ...this.optionallyAttachAccount(),
485
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
486
+ ...(params as any),
487
+ },
488
+ );
489
+ const hash = await writeSignerValidatorSetValidatorCaller(
490
+ this._config,
491
+ request,
492
+ );
493
+ return { hash, result };
494
+ }
495
+
496
+ /**
497
+ * Update the authorized caller of the validator function
498
+ *
499
+ * @public
500
+ * @async
501
+ * @param {Address} address
502
+ * @param {?WriteParams<typeof signerValidatorAbi, 'setValidatorCaller'>} [params]
503
+ * @returns {unknown}
504
+ */
505
+ public async setValidatorCaller(
506
+ address: Address,
507
+ params?: WriteParams<typeof signerValidatorAbi, 'setValidatorCaller'>,
508
+ ) {
509
+ return await this.awaitResult(this.setValidatorCallerRaw(address, params));
510
+ }
511
+
512
+ /**
513
+ * Properly encodes the data needed to claim
514
+ *
515
+ * @public
516
+ * @async
517
+ * @param {SignerValidatorClaimDataParams} params
518
+ * @returns {Promise<Hex>}
519
+ */
520
+ public async encodeClaimData(
521
+ params: Omit<SignerValidatorClaimDataParams, 'validator'>,
522
+ ): Promise<Hex> {
523
+ return await prepareSignerValidatorClaimDataPayload({
524
+ ...params,
525
+ validator: this.assertValidAddress(),
526
+ });
527
+ }
528
+
529
+ /**
530
+ * @inheritdoc
531
+ *
532
+ * @public
533
+ * @param {?SignerValidatorPayload} [_payload]
534
+ * @param {?DeployableOptions} [_options]
535
+ * @returns {GenericDeployableParams}
536
+ */
537
+ public override buildParameters(
538
+ _payload?: SignerValidatorPayload,
539
+ _options?: DeployableOptions,
540
+ ): GenericDeployableParams {
541
+ const [payload, options] = this.validateDeploymentConfig(
542
+ _payload,
543
+ _options,
544
+ );
545
+ return {
546
+ abi: signerValidatorAbi,
547
+ bytecode: bytecode as Hex,
548
+ args: [prepareSignerValidatorPayload(payload)],
549
+ ...this.optionallyAttachAccount(options.account),
550
+ };
551
+ }
552
+ }
553
+
554
+ /**
555
+ * Signer Validator Claim Data Payload Preparation
556
+ *
557
+ * @export
558
+ * @async
559
+ * @param {SignerValidatorClaimDataParams} param0
560
+ * @param {{ account: Address; key: Hex; privateKey: PrivateKeyAccount; }} param0.signer
561
+ * @param {Hex} param0.incentiveData
562
+ * @param {number} param0.chainId
563
+ * @param {Address} param0.validator
564
+ * @param {number} param0.incentiveQuantity
565
+ * @param {Address} param0.claimant
566
+ * @param {bigint} param0.boostId
567
+ * @returns {Promise<Hex>}
568
+ */
569
+ export async function prepareSignerValidatorClaimDataPayload({
570
+ signer,
571
+ incentiveData,
572
+ chainId,
573
+ validator,
574
+ incentiveQuantity,
575
+ claimant,
576
+ boostId,
577
+ }: SignerValidatorClaimDataParams): Promise<Hex> {
578
+ const domain = {
579
+ name: 'SignerValidator',
580
+ version: '1',
581
+ chainId: chainId,
582
+ verifyingContract: validator,
583
+ };
584
+ const typedData = {
585
+ domain,
586
+ types: {
587
+ SignerValidatorData: [
588
+ { name: 'boostId', type: 'uint256' },
589
+ { name: 'incentiveQuantity', type: 'uint8' },
590
+ { name: 'claimant', type: 'address' },
591
+ { name: 'incentiveData', type: 'bytes' },
592
+ ],
593
+ },
594
+ primaryType: 'SignerValidatorData' as const,
595
+ message: {
596
+ boostId,
597
+ incentiveQuantity,
598
+ claimant,
599
+ incentiveData: incentiveData,
600
+ },
601
+ };
602
+
603
+ const trustedSignature = await signTypedData({
604
+ ...typedData,
605
+ privateKey: signer.key,
606
+ });
607
+
608
+ // Prepare the claim data payload using the new helper
609
+ const validatorData = prepareSignerValidatorInputParams({
610
+ signer: signer.account,
611
+ signature: trustedSignature,
612
+ incentiveQuantity, // Adjust incentive quantity as necessary
613
+ });
614
+
615
+ const boostClaimDataPayload = encodeAbiParameters(
616
+ [
617
+ {
618
+ type: 'tuple',
619
+ name: 'BoostClaimData',
620
+ components: [
621
+ { type: 'bytes', name: 'validatorData' },
622
+ { type: 'bytes', name: 'incentiveData' },
623
+ ],
624
+ },
625
+ ],
626
+ [{ validatorData, incentiveData }],
627
+ );
628
+
629
+ return boostClaimDataPayload;
630
+ }
631
+
632
+ /**
633
+ * Given a {@link SignerValidatorInputParams}, properly encode the initialization payload.
634
+ *
635
+ * @param {SignerValidatorInputParams} param0
636
+ * @param {Address} param0.signer
637
+ * @param {Hex} param0.signature
638
+ * @param {number} param0.incentiveQuantity
639
+ * @returns {Hex}
640
+ */
641
+ export function prepareSignerValidatorInputParams({
642
+ signer,
643
+ signature,
644
+ incentiveQuantity,
645
+ }: SignerValidatorInputParams) {
646
+ return encodeAbiParameters(
647
+ [
648
+ {
649
+ type: 'tuple',
650
+ name: 'SignerValidatorInputParams',
651
+ components: [
652
+ { type: 'address', name: 'signer' },
653
+ { type: 'bytes', name: 'signature' },
654
+ { type: 'uint8', name: 'incentiveQuantity' },
655
+ ],
656
+ },
657
+ ],
658
+ [{ signer, signature, incentiveQuantity }],
659
+ );
660
+ }
661
+
662
+ /**
663
+ * Given a {@link SignerValidatorPayload}, properly encode the initialization payload.
664
+ *
665
+ * @param {SignerValidatorPayload} param0
666
+ * @param {Address[]} param0.signers
667
+ * @param {Address} param0.validatorCaller
668
+ * @returns {Hex}
669
+ */
670
+ export function prepareSignerValidatorPayload({
671
+ signers,
672
+ validatorCaller,
673
+ }: SignerValidatorPayload) {
674
+ return encodeAbiParameters(
675
+ [
676
+ { type: 'address[]', name: 'signers' },
677
+ { type: 'address', name: 'validatorCaller' },
678
+ ],
679
+ [signers, validatorCaller],
680
+ );
681
+ }
@@ -0,0 +1,21 @@
1
+ import { describe, expect, test } from 'vitest';
2
+ import { defaultOptions } from '../../test/helpers';
3
+ import { testAccount } from '../../test/viem';
4
+ import { SignerValidator } from './SignerValidator';
5
+ import { validatorFromAddress } from './Validator';
6
+
7
+ describe('Validator', () => {
8
+ test('can automatically instantiate SignerValidator given an address', async () => {
9
+ const validator = new SignerValidator(defaultOptions, {
10
+ signers: [testAccount.address],
11
+ validatorCaller: testAccount.address,
12
+ });
13
+ await validator.deploy();
14
+ expect(
15
+ await validatorFromAddress(
16
+ defaultOptions,
17
+ validator.assertValidAddress(),
18
+ ),
19
+ ).toBeInstanceOf(SignerValidator);
20
+ });
21
+ });