@boostxyz/sdk 0.0.0-alpha.3 → 0.0.0-alpha.6

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 (176) hide show
  1. package/dist/Actions/Action.cjs +2 -1
  2. package/dist/Actions/Action.cjs.map +1 -0
  3. package/dist/Actions/Action.d.ts +1 -1
  4. package/dist/Actions/Action.d.ts.map +1 -1
  5. package/dist/Actions/Action.js +15 -13
  6. package/dist/Actions/Action.js.map +1 -0
  7. package/dist/Actions/EventAction.cjs +1 -0
  8. package/dist/Actions/EventAction.cjs.map +1 -0
  9. package/dist/Actions/EventAction.js +1 -0
  10. package/dist/Actions/EventAction.js.map +1 -0
  11. package/dist/AllowLists/AllowList.cjs +2 -1
  12. package/dist/AllowLists/AllowList.cjs.map +1 -0
  13. package/dist/AllowLists/AllowList.d.ts +1 -2
  14. package/dist/AllowLists/AllowList.d.ts.map +1 -1
  15. package/dist/AllowLists/AllowList.js +16 -14
  16. package/dist/AllowLists/AllowList.js.map +1 -0
  17. package/dist/AllowLists/SimpleAllowList.cjs +1 -0
  18. package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
  19. package/dist/AllowLists/SimpleAllowList.js +1 -0
  20. package/dist/AllowLists/SimpleAllowList.js.map +1 -0
  21. package/dist/AllowLists/SimpleDenyList.cjs +1 -0
  22. package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
  23. package/dist/AllowLists/SimpleDenyList.js +1 -0
  24. package/dist/AllowLists/SimpleDenyList.js.map +1 -0
  25. package/dist/Auth/Auth.cjs +1 -0
  26. package/dist/Auth/Auth.cjs.map +1 -0
  27. package/dist/Auth/Auth.js +1 -0
  28. package/dist/Auth/Auth.js.map +1 -0
  29. package/dist/Auth/PassthroughAuth.cjs +1 -0
  30. package/dist/Auth/PassthroughAuth.cjs.map +1 -0
  31. package/dist/Auth/PassthroughAuth.js +1 -0
  32. package/dist/Auth/PassthroughAuth.js.map +1 -0
  33. package/dist/Boost.cjs +1 -0
  34. package/dist/Boost.cjs.map +1 -0
  35. package/dist/Boost.js +1 -0
  36. package/dist/Boost.js.map +1 -0
  37. package/dist/BoostCore.cjs +1 -0
  38. package/dist/BoostCore.cjs.map +1 -0
  39. package/dist/BoostCore.js +1 -0
  40. package/dist/BoostCore.js.map +1 -0
  41. package/dist/BoostRegistry.cjs +1 -0
  42. package/dist/BoostRegistry.cjs.map +1 -0
  43. package/dist/BoostRegistry.js +1 -0
  44. package/dist/BoostRegistry.js.map +1 -0
  45. package/dist/Budgets/Budget.cjs +2 -1
  46. package/dist/Budgets/Budget.cjs.map +1 -0
  47. package/dist/Budgets/Budget.d.ts +1 -1
  48. package/dist/Budgets/Budget.d.ts.map +1 -1
  49. package/dist/Budgets/Budget.js +14 -12
  50. package/dist/Budgets/Budget.js.map +1 -0
  51. package/dist/Budgets/ManagedBudget.cjs +1 -0
  52. package/dist/Budgets/ManagedBudget.cjs.map +1 -0
  53. package/dist/Budgets/ManagedBudget.js +1 -0
  54. package/dist/Budgets/ManagedBudget.js.map +1 -0
  55. package/dist/Deployable/Contract.cjs +1 -0
  56. package/dist/Deployable/Contract.cjs.map +1 -0
  57. package/dist/Deployable/Contract.js +1 -0
  58. package/dist/Deployable/Contract.js.map +1 -0
  59. package/dist/Deployable/Deployable.cjs +1 -0
  60. package/dist/Deployable/Deployable.cjs.map +1 -0
  61. package/dist/Deployable/Deployable.js +1 -0
  62. package/dist/Deployable/Deployable.js.map +1 -0
  63. package/dist/Deployable/DeployableTarget.cjs +1 -0
  64. package/dist/Deployable/DeployableTarget.cjs.map +1 -0
  65. package/dist/Deployable/DeployableTarget.js +1 -0
  66. package/dist/Deployable/DeployableTarget.js.map +1 -0
  67. package/dist/Incentives/AllowListIncentive.cjs +1 -0
  68. package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
  69. package/dist/Incentives/AllowListIncentive.js +1 -0
  70. package/dist/Incentives/AllowListIncentive.js.map +1 -0
  71. package/dist/Incentives/CGDAIncentive.cjs +1 -0
  72. package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
  73. package/dist/Incentives/CGDAIncentive.js +1 -0
  74. package/dist/Incentives/CGDAIncentive.js.map +1 -0
  75. package/dist/Incentives/ERC20Incentive.cjs +1 -0
  76. package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
  77. package/dist/Incentives/ERC20Incentive.js +1 -0
  78. package/dist/Incentives/ERC20Incentive.js.map +1 -0
  79. package/dist/Incentives/Incentive.cjs +2 -1
  80. package/dist/Incentives/Incentive.cjs.map +1 -0
  81. package/dist/Incentives/Incentive.d.ts +1 -4
  82. package/dist/Incentives/Incentive.d.ts.map +1 -1
  83. package/dist/Incentives/Incentive.js +39 -36
  84. package/dist/Incentives/Incentive.js.map +1 -0
  85. package/dist/Incentives/PointsIncentive.cjs +1 -0
  86. package/dist/Incentives/PointsIncentive.cjs.map +1 -0
  87. package/dist/Incentives/PointsIncentive.js +1 -0
  88. package/dist/Incentives/PointsIncentive.js.map +1 -0
  89. package/dist/Validators/SignerValidator.cjs +1 -0
  90. package/dist/Validators/SignerValidator.cjs.map +1 -0
  91. package/dist/Validators/SignerValidator.js +1 -0
  92. package/dist/Validators/SignerValidator.js.map +1 -0
  93. package/dist/Validators/Validator.cjs +2 -1
  94. package/dist/Validators/Validator.cjs.map +1 -0
  95. package/dist/Validators/Validator.d.ts +1 -1
  96. package/dist/Validators/Validator.d.ts.map +1 -1
  97. package/dist/Validators/Validator.js +9 -7
  98. package/dist/Validators/Validator.js.map +1 -0
  99. package/dist/componentInterfaces-CKCBwG16.cjs +2 -0
  100. package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
  101. package/dist/componentInterfaces-DYkaxBda.js +13 -0
  102. package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
  103. package/dist/errors.cjs +1 -0
  104. package/dist/errors.cjs.map +1 -0
  105. package/dist/errors.js +1 -0
  106. package/dist/errors.js.map +1 -0
  107. package/dist/generated-Cd-Fe7W7.cjs +1 -0
  108. package/dist/generated-Cd-Fe7W7.cjs.map +1 -0
  109. package/dist/generated-DGpIVcv5.js +1 -0
  110. package/dist/generated-DGpIVcv5.js.map +1 -0
  111. package/dist/index.cjs +1 -0
  112. package/dist/index.cjs.map +1 -0
  113. package/dist/index.js +1 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/utils.cjs +1 -0
  116. package/dist/utils.cjs.map +1 -0
  117. package/dist/utils.d.ts +1 -1
  118. package/dist/utils.d.ts.map +1 -1
  119. package/dist/utils.js +1 -0
  120. package/dist/utils.js.map +1 -0
  121. package/package.json +5 -3
  122. package/src/Actions/Action.test.ts +77 -0
  123. package/src/Actions/Action.ts +61 -0
  124. package/src/Actions/ContractAction.test.ts +199 -0
  125. package/src/Actions/ContractAction.ts +238 -0
  126. package/src/Actions/ERC721MintAction.test.ts +112 -0
  127. package/src/Actions/ERC721MintAction.ts +238 -0
  128. package/src/Actions/EventAction.test.ts +182 -0
  129. package/src/Actions/EventAction.ts +382 -0
  130. package/src/AllowLists/AllowList.test.ts +64 -0
  131. package/src/AllowLists/AllowList.ts +60 -0
  132. package/src/AllowLists/SimpleAllowList.test.ts +52 -0
  133. package/src/AllowLists/SimpleAllowList.ts +240 -0
  134. package/src/AllowLists/SimpleDenyList.test.ts +52 -0
  135. package/src/AllowLists/SimpleDenyList.ts +289 -0
  136. package/src/Auth/Auth.ts +11 -0
  137. package/src/Auth/PassthroughAuth.test.ts +12 -0
  138. package/src/Auth/PassthroughAuth.ts +80 -0
  139. package/src/Boost.ts +155 -0
  140. package/src/BoostCore.test.ts +846 -0
  141. package/src/BoostCore.ts +1192 -0
  142. package/src/BoostRegistry.ts +449 -0
  143. package/src/Budgets/Budget.test.ts +27 -0
  144. package/src/Budgets/Budget.ts +61 -0
  145. package/src/Budgets/ManagedBudget.test.ts +154 -0
  146. package/src/Budgets/ManagedBudget.ts +743 -0
  147. package/src/Budgets/SimpleBudget.test.ts +152 -0
  148. package/src/Budgets/SimpleBudget.ts +521 -0
  149. package/src/Budgets/VestingBudget.test.ts +123 -0
  150. package/src/Budgets/VestingBudget.ts +532 -0
  151. package/src/Deployable/Contract.ts +229 -0
  152. package/src/Deployable/Deployable.ts +244 -0
  153. package/src/Deployable/DeployableTarget.ts +210 -0
  154. package/src/Incentives/AllowListIncentive.test.ts +146 -0
  155. package/src/Incentives/AllowListIncentive.ts +290 -0
  156. package/src/Incentives/CGDAIncentive.test.ts +136 -0
  157. package/src/Incentives/CGDAIncentive.ts +364 -0
  158. package/src/Incentives/ERC1155Incentive.test.ts +98 -0
  159. package/src/Incentives/ERC1155Incentive.ts +384 -0
  160. package/src/Incentives/ERC20Incentive.test.ts +141 -0
  161. package/src/Incentives/ERC20Incentive.ts +417 -0
  162. package/src/Incentives/ERC20VariableIncentive.test.ts +156 -0
  163. package/src/Incentives/ERC20VariableIncentive.ts +368 -0
  164. package/src/Incentives/Incentive.test.ts +92 -0
  165. package/src/Incentives/Incentive.ts +85 -0
  166. package/src/Incentives/PointsIncentive.test.ts +142 -0
  167. package/src/Incentives/PointsIncentive.ts +303 -0
  168. package/src/Validators/SignerValidator.test.ts +163 -0
  169. package/src/Validators/SignerValidator.ts +272 -0
  170. package/src/Validators/Validator.test.ts +21 -0
  171. package/src/Validators/Validator.ts +55 -0
  172. package/src/errors.ts +524 -0
  173. package/src/index.test.ts +40 -0
  174. package/src/index.ts +50 -0
  175. package/src/utils.test.ts +44 -0
  176. package/src/utils.ts +2247 -0
@@ -0,0 +1,368 @@
1
+ import {
2
+ erc20VariableIncentiveAbi,
3
+ readErc20VariableIncentiveAsset,
4
+ readErc20VariableIncentiveClaimed,
5
+ readErc20VariableIncentiveClaims,
6
+ readErc20VariableIncentiveCurrentReward,
7
+ readErc20VariableIncentiveIsClaimable,
8
+ readErc20VariableIncentiveLimit,
9
+ readErc20VariableIncentiveOwner,
10
+ readErc20VariableIncentiveReward,
11
+ readErc20VariableIncentiveTotalClaimed,
12
+ simulateErc20VariableIncentiveClaim,
13
+ simulateErc20VariableIncentiveClawback,
14
+ writeErc20VariableIncentiveClaim,
15
+ writeErc20VariableIncentiveClawback,
16
+ } from '@boostxyz/evm';
17
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/incentives/ERC20VariableIncentive.sol/ERC20VariableIncentive.json';
18
+ import type { Address, ContractEventName, Hex } from 'viem';
19
+ import type {
20
+ DeployableOptions,
21
+ GenericDeployableParams,
22
+ } from '../Deployable/Deployable';
23
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
24
+ import {
25
+ type ClaimPayload,
26
+ type ERC20VariableIncentivePayload,
27
+ type GenericLog,
28
+ type ReadParams,
29
+ RegistryType,
30
+ type WriteParams,
31
+ prepareClaimPayload,
32
+ prepareERC20VariableIncentivePayload,
33
+ } from '../utils';
34
+
35
+ export { erc20VariableIncentiveAbi };
36
+ export type { ERC20VariableIncentivePayload };
37
+
38
+ /**
39
+ * A generic `viem.Log` event with support for `ERC20VariableIncentive` event types.
40
+ *
41
+ * @export
42
+ * @typedef {ERC20VariableIncentiveLog}
43
+ * @template {ContractEventName<typeof erc20VariableIncentiveAbi>} [event=ContractEventName<
44
+ * typeof erc20VariableIncentiveAbi
45
+ * >]
46
+ */
47
+ export type ERC20VariableIncentiveLog<
48
+ event extends ContractEventName<
49
+ typeof erc20VariableIncentiveAbi
50
+ > = ContractEventName<typeof erc20VariableIncentiveAbi>,
51
+ > = GenericLog<typeof erc20VariableIncentiveAbi, event>;
52
+
53
+ /**
54
+ * A simple ERC20 incentive implementation that allows claiming of tokens
55
+ *
56
+ * @export
57
+ * @class ERC20VariableIncentive
58
+ * @typedef {ERC20VariableIncentive}
59
+ * @extends {DeployableTarget<ERC20VariableIncentivePayload>}
60
+ */
61
+ export class ERC20VariableIncentive extends DeployableTarget<
62
+ ERC20VariableIncentivePayload,
63
+ typeof erc20VariableIncentiveAbi
64
+ > {
65
+ public override readonly abi = erc20VariableIncentiveAbi;
66
+ /**
67
+ * @inheritdoc
68
+ *
69
+ * @public
70
+ * @static
71
+ * @type {Address}
72
+ */
73
+ public static override base: Address = import.meta.env
74
+ .VITE_ERC20_VARIABLE_INCENTIVE_BASE;
75
+ /**
76
+ * @inheritdoc
77
+ *
78
+ * @public
79
+ * @static
80
+ * @type {RegistryType}
81
+ */
82
+ public static override registryType: RegistryType = RegistryType.INCENTIVE;
83
+
84
+ /**
85
+ * The owner of the incentive
86
+ *
87
+ * @public
88
+ * @async
89
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'owner'>} [params]
90
+ * @returns {unknown}
91
+ */
92
+ public async owner(
93
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'owner'>,
94
+ ) {
95
+ return readErc20VariableIncentiveOwner(this._config, {
96
+ address: this.assertValidAddress(),
97
+ args: [],
98
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
99
+ ...(params as any),
100
+ });
101
+ }
102
+
103
+ /**
104
+ * The current reward
105
+ *
106
+ * @public
107
+ * @async
108
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'currentReward'>} [params]
109
+ * @returns {Promise<bigint>} - The current reward
110
+ */
111
+ public async totalClaimed(
112
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'totalClaimed'>,
113
+ ) {
114
+ return readErc20VariableIncentiveTotalClaimed(this._config, {
115
+ address: this.assertValidAddress(),
116
+ args: [],
117
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
118
+ ...(params as any),
119
+ });
120
+ }
121
+
122
+ /**
123
+ * The current reward
124
+ *
125
+ * @public
126
+ * @async
127
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'currentReward'>} [params]
128
+ * @returns {Promise<bigint>} - The current reward
129
+ */
130
+ public async currentReward(
131
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'currentReward'>,
132
+ ) {
133
+ return readErc20VariableIncentiveCurrentReward(this._config, {
134
+ address: this.assertValidAddress(),
135
+ args: [],
136
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
137
+ ...(params as any),
138
+ });
139
+ }
140
+
141
+ /**
142
+ * The number of claims that have been made
143
+ *
144
+ * @public
145
+ * @async
146
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'claims'>} [params]
147
+ * @returns {Promise<bigint>}
148
+ */
149
+ public async claims(
150
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'claims'>,
151
+ ) {
152
+ return readErc20VariableIncentiveClaims(this._config, {
153
+ address: this.assertValidAddress(),
154
+ args: [],
155
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
156
+ ...(params as any),
157
+ });
158
+ }
159
+
160
+ /**
161
+ * A mapping of address to claim status
162
+ *
163
+ * @public
164
+ * @async
165
+ * @param {Address} address
166
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'claimed'>} [params]
167
+ * @returns {Promise<boolean>}
168
+ */
169
+ public async claimed(
170
+ address: Address,
171
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'claimed'>,
172
+ ) {
173
+ return readErc20VariableIncentiveClaimed(this._config, {
174
+ address: this.assertValidAddress(),
175
+ args: [address],
176
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
177
+ ...(params as any),
178
+ });
179
+ }
180
+
181
+ /**
182
+ * The address of the ERC20-like token
183
+ *
184
+ * @public
185
+ * @async
186
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'asset'>} [params]
187
+ * @returns {Promise<Address>}
188
+ */
189
+ public async asset(
190
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'asset'>,
191
+ ) {
192
+ return readErc20VariableIncentiveAsset(this._config, {
193
+ address: this.assertValidAddress(),
194
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
195
+ ...(params as any),
196
+ });
197
+ }
198
+
199
+ /**
200
+ * The reward amount issued for each claim
201
+ *
202
+ * @public
203
+ * @async
204
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'reward'>} [params]
205
+ * @returns {Promise<bigint>}
206
+ */
207
+ public async reward(
208
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'reward'>,
209
+ ) {
210
+ return readErc20VariableIncentiveReward(this._config, {
211
+ address: this.assertValidAddress(),
212
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
213
+ ...(params as any),
214
+ });
215
+ }
216
+
217
+ /**
218
+ * The limit (max claims, or max entries for raffles)
219
+ *
220
+ * @public
221
+ * @async
222
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'limit'>} [params]
223
+ * @returns {unknown}
224
+ */
225
+ public async limit(
226
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'limit'>,
227
+ ) {
228
+ return readErc20VariableIncentiveLimit(this._config, {
229
+ address: this.assertValidAddress(),
230
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
231
+ ...(params as any),
232
+ });
233
+ }
234
+
235
+ /**
236
+ * Claim the incentive
237
+ *
238
+ * @public
239
+ * @async
240
+ * @param {ClaimPayload} payload
241
+ * @param {?WriteParams<typeof erc20VariableIncentiveAbi, 'claim'>} [params]
242
+ * @returns {Promise<boolean>} - Returns true if successfully claimed
243
+ */
244
+ public async claim(
245
+ payload: ClaimPayload,
246
+ params?: WriteParams<typeof erc20VariableIncentiveAbi, 'claim'>,
247
+ ) {
248
+ return this.awaitResult(this.claimRaw(payload, params));
249
+ }
250
+
251
+ /**
252
+ * Claim the incentive
253
+ *
254
+ * @public
255
+ * @async
256
+ * @param {ClaimPayload} payload
257
+ * @param {?WriteParams<typeof erc20VariableIncentiveAbi, 'claim'>} [params]
258
+ * @returns {Promise<boolean>} - Returns true if successfully claimed
259
+ */
260
+ public async claimRaw(
261
+ payload: ClaimPayload,
262
+ params?: WriteParams<typeof erc20VariableIncentiveAbi, 'claim'>,
263
+ ) {
264
+ const { request, result } = await simulateErc20VariableIncentiveClaim(
265
+ this._config,
266
+ {
267
+ address: this.assertValidAddress(),
268
+ args: [prepareClaimPayload(payload)],
269
+ ...this.optionallyAttachAccount(),
270
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
271
+ ...(params as any),
272
+ },
273
+ );
274
+ const hash = await writeErc20VariableIncentiveClaim(this._config, request);
275
+ return { hash, result };
276
+ }
277
+
278
+ /**
279
+ * Clawback assets from the incentive
280
+ *
281
+ * @public
282
+ * @async
283
+ * @param {ClaimPayload} payload
284
+ * @param {?WriteParams<typeof erc20VariableIncentiveAbi, 'clawback'>} [params]
285
+ * @returns {Promise<boolean>} - True if the assets were successfully clawbacked
286
+ */
287
+ public async clawback(
288
+ payload: ClaimPayload,
289
+ params?: WriteParams<typeof erc20VariableIncentiveAbi, 'clawback'>,
290
+ ) {
291
+ return this.awaitResult(this.clawbackRaw(payload, params));
292
+ }
293
+
294
+ /**
295
+ * Clawback assets from the incentive
296
+ *
297
+ * @public
298
+ * @async
299
+ * @param {ClaimPayload} payload
300
+ * @param {?WriteParams<typeof erc20VariableIncentiveAbi, 'clawback'>} [params]
301
+ * @returns {Promise<boolean>} - True if the assets were successfully clawbacked
302
+ */
303
+ public async clawbackRaw(
304
+ payload: ClaimPayload,
305
+ params?: WriteParams<typeof erc20VariableIncentiveAbi, 'clawback'>,
306
+ ) {
307
+ const { request, result } = await simulateErc20VariableIncentiveClawback(
308
+ this._config,
309
+ {
310
+ address: this.assertValidAddress(),
311
+ args: [prepareClaimPayload(payload)],
312
+ ...this.optionallyAttachAccount(),
313
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
314
+ ...(params as any),
315
+ },
316
+ );
317
+ const hash = await writeErc20VariableIncentiveClawback(
318
+ this._config,
319
+ request,
320
+ );
321
+ return { hash, result };
322
+ }
323
+
324
+ /**
325
+ * Check if an incentive is claimable. For the POOL strategy, the `bytes data` portion of the payload ignored. The recipient must not have already claimed the incentive.
326
+ *
327
+ * @public
328
+ * @async
329
+ * @param {ClaimPayload} payload
330
+ * @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'isClaimable'>} [params]
331
+ * @returns {unknown} = True if the incentive is claimable based on the data payload
332
+ */
333
+ public async isClaimable(
334
+ payload: ClaimPayload,
335
+ params?: ReadParams<typeof erc20VariableIncentiveAbi, 'isClaimable'>,
336
+ ) {
337
+ return readErc20VariableIncentiveIsClaimable(this._config, {
338
+ address: this.assertValidAddress(),
339
+ args: [prepareClaimPayload(payload)],
340
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
341
+ ...(params as any),
342
+ });
343
+ }
344
+
345
+ /**
346
+ * @inheritdoc
347
+ *
348
+ * @public
349
+ * @param {?ERC20VariableIncentivePayload} [_payload]
350
+ * @param {?DeployableOptions} [_options]
351
+ * @returns {GenericDeployableParams}
352
+ */
353
+ public override buildParameters(
354
+ _payload?: ERC20VariableIncentivePayload,
355
+ _options?: DeployableOptions,
356
+ ): GenericDeployableParams {
357
+ const [payload, options] = this.validateDeploymentConfig(
358
+ _payload,
359
+ _options,
360
+ );
361
+ return {
362
+ abi: erc20VariableIncentiveAbi,
363
+ bytecode: bytecode as Hex,
364
+ args: [prepareERC20VariableIncentivePayload(payload)],
365
+ ...this.optionallyAttachAccount(options.account),
366
+ };
367
+ }
368
+ }
@@ -0,0 +1,92 @@
1
+ import { zeroAddress } from 'viem';
2
+ import { describe, expect, test } from 'vitest';
3
+ import { defaultOptions } from '../../test/helpers';
4
+ import { StrategyType } from '../utils';
5
+ import {
6
+ AllowListIncentive,
7
+ CGDAIncentive,
8
+ ERC20Incentive,
9
+ ERC20VariableIncentive,
10
+ incentiveFromAddress,
11
+ } from './Incentive';
12
+ import { PointsIncentive } from './PointsIncentive';
13
+
14
+ describe('Incentive', () => {
15
+ test('can automatically instantiate PointsIncentive given an address', async () => {
16
+ const incentive = new PointsIncentive(defaultOptions, {
17
+ venue: zeroAddress,
18
+ selector: '0xdeadb33f',
19
+ reward: 1n,
20
+ limit: 1n,
21
+ });
22
+ await incentive.deploy();
23
+ expect(
24
+ await incentiveFromAddress(
25
+ defaultOptions,
26
+ incentive.assertValidAddress(),
27
+ ),
28
+ ).toBeInstanceOf(PointsIncentive);
29
+ });
30
+
31
+ test('can automatically instantiate AllowListIncentive given an address', async () => {
32
+ const incentive = new AllowListIncentive(defaultOptions, {
33
+ allowList: zeroAddress,
34
+ limit: 3n,
35
+ });
36
+ await incentive.deploy();
37
+ expect(
38
+ await incentiveFromAddress(
39
+ defaultOptions,
40
+ incentive.assertValidAddress(),
41
+ ),
42
+ ).toBeInstanceOf(AllowListIncentive);
43
+ });
44
+
45
+ test('can automatically instantiate CGDAIncentive given an address', async () => {
46
+ const incentive = new CGDAIncentive(defaultOptions, {
47
+ asset: zeroAddress,
48
+ initialReward: 1n,
49
+ totalBudget: 10n,
50
+ rewardBoost: 1n,
51
+ rewardDecay: 1n,
52
+ });
53
+ await incentive.deploy();
54
+ expect(
55
+ await incentiveFromAddress(
56
+ defaultOptions,
57
+ incentive.assertValidAddress(),
58
+ ),
59
+ ).toBeInstanceOf(CGDAIncentive);
60
+ });
61
+
62
+ test('can automatically instantiate ERC20Incentive given an address', async () => {
63
+ const incentive = new ERC20Incentive(defaultOptions, {
64
+ asset: zeroAddress,
65
+ strategy: StrategyType.POOL,
66
+ reward: 1n,
67
+ limit: 10n,
68
+ });
69
+ await incentive.deploy();
70
+ expect(
71
+ await incentiveFromAddress(
72
+ defaultOptions,
73
+ incentive.assertValidAddress(),
74
+ ),
75
+ ).toBeInstanceOf(ERC20Incentive);
76
+ });
77
+
78
+ test('can automatically instantiate ERC20VariableIncentive given an address', async () => {
79
+ const incentive = new ERC20VariableIncentive(defaultOptions, {
80
+ asset: zeroAddress,
81
+ reward: 1n,
82
+ limit: 10n,
83
+ });
84
+ await incentive.deploy();
85
+ expect(
86
+ await incentiveFromAddress(
87
+ defaultOptions,
88
+ incentive.assertValidAddress(),
89
+ ),
90
+ ).toBeInstanceOf(ERC20VariableIncentive);
91
+ });
92
+ });
@@ -0,0 +1,85 @@
1
+ import { aIncentiveAbi } from '@boostxyz/evm';
2
+ import {
3
+ AAllowListIncentive,
4
+ ACGDAIncentive,
5
+ AERC20Incentive,
6
+ AERC20VariableIncentive,
7
+ APointsIncentive,
8
+ } from '@boostxyz/evm/deploys/componentInterfaces.json';
9
+ import { readContract } from '@wagmi/core';
10
+ import type { Address, Hex } from 'viem';
11
+ import type { DeployableOptions } from '../Deployable/Deployable';
12
+ import { InvalidComponentInterfaceError } from '../errors';
13
+ import { AllowListIncentive } from './AllowListIncentive';
14
+ import { CGDAIncentive } from './CGDAIncentive';
15
+ import { ERC20Incentive } from './ERC20Incentive';
16
+ import { ERC20VariableIncentive } from './ERC20VariableIncentive';
17
+ // import { ERC1155Incentive } from './ERC1155Incentive';
18
+ import { PointsIncentive } from './PointsIncentive';
19
+
20
+ export {
21
+ AllowListIncentive,
22
+ CGDAIncentive,
23
+ // ERC1155Incentive,
24
+ ERC20Incentive,
25
+ PointsIncentive,
26
+ ERC20VariableIncentive,
27
+ };
28
+
29
+ /**
30
+ * A union type representing all valid protocol Incentive implementations
31
+ *
32
+ * @export
33
+ * @typedef {Incentive}
34
+ */
35
+ export type Incentive =
36
+ | AllowListIncentive
37
+ | CGDAIncentive
38
+ | ERC20Incentive
39
+ // | ERC1155Incentive
40
+ | PointsIncentive
41
+ | ERC20VariableIncentive;
42
+
43
+ /**
44
+ * A map of Incentive component interfaces to their constructors.
45
+ *
46
+ * @type {{ "0xc5b24b8e": typeof PointsIncentive; "0x8c901437": typeof ERC20Incentive; "0x0a466e6f": typeof AllowListIncentive; "0xa39e44d9": typeof CGDAIncentive; "0x6060409d": typeof ERC20VariableIncentive }}
47
+ */
48
+ export const IncentiveByComponentInterface = {
49
+ [APointsIncentive as Hex]: PointsIncentive,
50
+ [AERC20Incentive as Hex]: ERC20Incentive,
51
+ // TODO: figure out why evm generates bad bytes4 here
52
+ ['0x0a466e6f']: AllowListIncentive,
53
+ // [APointsIncentive as Hex]: ERC1155Incentive,
54
+ [ACGDAIncentive as Hex]: CGDAIncentive,
55
+ [AERC20VariableIncentive as Hex]: ERC20VariableIncentive,
56
+ };
57
+
58
+ /**
59
+ * A function that will read a contract's component interface using `getComponentInterface` and return the correct instantiated instance.
60
+ *
61
+ * @export
62
+ * @async
63
+ * @param {DeployableOptions} options
64
+ * @param {Address} address
65
+ * @returns {unknown}
66
+ * @throws {@link InvalidComponentInterfaceError}
67
+ */
68
+ export async function incentiveFromAddress(
69
+ options: DeployableOptions,
70
+ address: Address,
71
+ ) {
72
+ const interfaceId = (await readContract(options.config, {
73
+ abi: aIncentiveAbi,
74
+ functionName: 'getComponentInterface',
75
+ address,
76
+ })) as keyof typeof IncentiveByComponentInterface;
77
+ const Ctor = IncentiveByComponentInterface[interfaceId];
78
+ if (!Ctor) {
79
+ throw new InvalidComponentInterfaceError(
80
+ Object.keys(IncentiveByComponentInterface) as Hex[],
81
+ interfaceId as Hex,
82
+ );
83
+ }
84
+ return new Ctor(options, address);
85
+ }
@@ -0,0 +1,142 @@
1
+ import { readPointsBalanceOf, writePointsGrantRoles } from '@boostxyz/evm';
2
+ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
3
+ import { signMessage } from '@wagmi/core';
4
+ import { isAddress, pad, parseEther, zeroAddress } from 'viem';
5
+ import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
6
+ import type { MockPoints } from '../../test/MockPoints';
7
+ import { accounts } from '../../test/accounts';
8
+ import {
9
+ type Fixtures,
10
+ defaultOptions,
11
+ deployFixtures,
12
+ freshBoost,
13
+ freshPoints,
14
+ } from '../../test/helpers';
15
+ import { bytes4, prepareSignerValidatorClaimDataPayload } from '../utils';
16
+ import { PointsIncentive } from './PointsIncentive';
17
+
18
+ let fixtures: Fixtures, points: MockPoints;
19
+
20
+ describe('PointsIncentive', () => {
21
+ beforeAll(async () => {
22
+ fixtures = await loadFixture(deployFixtures);
23
+ });
24
+
25
+ beforeEach(async () => {
26
+ points = await loadFixture(freshPoints);
27
+ });
28
+
29
+ test('can successfully be deployed', async () => {
30
+ const action = new PointsIncentive(defaultOptions, {
31
+ venue: zeroAddress,
32
+ selector: '0xdeadb33f',
33
+ reward: 1n,
34
+ limit: 1n,
35
+ });
36
+ await action.deploy();
37
+ expect(isAddress(action.assertValidAddress())).toBe(true);
38
+ });
39
+
40
+ test('can claim', async () => {
41
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
42
+ const referrer = accounts.at(1)!.account!;
43
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
44
+ const trustedSigner = accounts.at(0)!;
45
+ const pointsIncentive = new fixtures.bases.PointsIncentive(defaultOptions, {
46
+ venue: points.assertValidAddress(),
47
+ selector: bytes4('issue(address,uint256)'),
48
+ reward: 1n,
49
+ limit: 10n,
50
+ });
51
+ const boost = await freshBoost(fixtures, {
52
+ incentives: [pointsIncentive],
53
+ });
54
+
55
+ const claimant = trustedSigner.account;
56
+ const incentiveData = pad('0xdef456232173821931823712381232131391321934');
57
+ const incentiveQuantity = 1;
58
+ const claimDataPayload = await prepareSignerValidatorClaimDataPayload({
59
+ signer: trustedSigner,
60
+ incentiveData,
61
+ chainId: defaultOptions.config.chains[0].id,
62
+ validator: boost.validator.assertValidAddress(),
63
+ incentiveQuantity,
64
+ claimant,
65
+ boostId: boost.id,
66
+ });
67
+
68
+ await writePointsGrantRoles(defaultOptions.config, {
69
+ address: points.assertValidAddress(),
70
+ args: [pointsIncentive.assertValidAddress(), 2n],
71
+ account: defaultOptions.account,
72
+ });
73
+ await fixtures.core.claimIncentive(
74
+ boost.id,
75
+ 0n,
76
+ referrer,
77
+ claimDataPayload,
78
+ { value: parseEther('0.000075') },
79
+ );
80
+ expect(
81
+ await readPointsBalanceOf(defaultOptions.config, {
82
+ address: points.assertValidAddress(),
83
+ args: [defaultOptions.account.address],
84
+ }),
85
+ ).toBe(1n);
86
+ });
87
+
88
+ test('cannot claim twice', async () => {
89
+ const reward = 1n;
90
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
91
+ const referrer = accounts.at(1)!.account!;
92
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
93
+ const trustedSigner = accounts.at(0)!;
94
+
95
+ const pointsIncentive = new fixtures.bases.PointsIncentive(defaultOptions, {
96
+ venue: points.assertValidAddress(),
97
+ selector: bytes4('issue(address,uint256)'),
98
+ reward,
99
+ limit: 10n,
100
+ });
101
+ const boost = await freshBoost(fixtures, {
102
+ incentives: [pointsIncentive],
103
+ });
104
+
105
+ const claimant = trustedSigner.account;
106
+ const incentiveData = pad('0xdef456232173821931823712381232131391321934');
107
+ const incentiveQuantity = 1;
108
+ const claimDataPayload = await prepareSignerValidatorClaimDataPayload({
109
+ signer: trustedSigner,
110
+ incentiveData,
111
+ chainId: defaultOptions.config.chains[0].id,
112
+ validator: boost.validator.assertValidAddress(),
113
+ incentiveQuantity,
114
+ claimant,
115
+ boostId: boost.id,
116
+ });
117
+
118
+ await writePointsGrantRoles(defaultOptions.config, {
119
+ address: points.assertValidAddress(),
120
+ args: [pointsIncentive.assertValidAddress(), 2n],
121
+ account: defaultOptions.account,
122
+ });
123
+ await fixtures.core.claimIncentive(
124
+ boost.id,
125
+ 0n,
126
+ referrer,
127
+ claimDataPayload,
128
+ { value: parseEther('0.000075') },
129
+ );
130
+ try {
131
+ await fixtures.core.claimIncentive(
132
+ boost.id,
133
+ 0n,
134
+ referrer,
135
+ claimDataPayload,
136
+ { value: parseEther('0.000075') },
137
+ );
138
+ } catch (e) {
139
+ expect(e).toBeInstanceOf(Error);
140
+ }
141
+ });
142
+ });