@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,417 @@
1
+ import {
2
+ erc20IncentiveAbi,
3
+ readErc20IncentiveAsset,
4
+ readErc20IncentiveClaimed,
5
+ readErc20IncentiveClaims,
6
+ readErc20IncentiveCurrentReward,
7
+ readErc20IncentiveEntries,
8
+ readErc20IncentiveIsClaimable,
9
+ readErc20IncentiveLimit,
10
+ readErc20IncentiveOwner,
11
+ readErc20IncentiveReward,
12
+ readErc20IncentiveStrategy,
13
+ simulateErc20IncentiveClaim,
14
+ simulateErc20IncentiveClawback,
15
+ simulateErc20IncentiveDrawRaffle,
16
+ writeErc20IncentiveClaim,
17
+ writeErc20IncentiveClawback,
18
+ writeErc20IncentiveDrawRaffle,
19
+ } from '@boostxyz/evm';
20
+ import { bytecode } from '@boostxyz/evm/artifacts/contracts/incentives/ERC20Incentive.sol/ERC20Incentive.json';
21
+ import type { Address, ContractEventName, Hex } from 'viem';
22
+ import type {
23
+ DeployableOptions,
24
+ GenericDeployableParams,
25
+ } from '../Deployable/Deployable';
26
+ import { DeployableTarget } from '../Deployable/DeployableTarget';
27
+ import {
28
+ type ClaimPayload,
29
+ type ERC20IncentivePayload,
30
+ type GenericLog,
31
+ type ReadParams,
32
+ RegistryType,
33
+ type StrategyType,
34
+ type WriteParams,
35
+ prepareClaimPayload,
36
+ prepareERC20IncentivePayload,
37
+ } from '../utils';
38
+
39
+ export { erc20IncentiveAbi };
40
+ export type { ERC20IncentivePayload };
41
+
42
+ /**
43
+ * A generic `viem.Log` event with support for `ERC20Incentive` event types.
44
+ *
45
+ * @export
46
+ * @typedef {ERC20IncentiveLog}
47
+ * @template {ContractEventName<typeof erc20IncentiveAbi>} [event=ContractEventName<
48
+ * typeof erc20IncentiveAbi
49
+ * >]
50
+ */
51
+ export type ERC20IncentiveLog<
52
+ event extends ContractEventName<typeof erc20IncentiveAbi> = ContractEventName<
53
+ typeof erc20IncentiveAbi
54
+ >,
55
+ > = GenericLog<typeof erc20IncentiveAbi, event>;
56
+
57
+ /**
58
+ * A simple ERC20 incentive implementation that allows claiming of tokens
59
+ *
60
+ * @export
61
+ * @class ERC20Incentive
62
+ * @typedef {ERC20Incentive}
63
+ * @extends {DeployableTarget<ERC20IncentivePayload>}
64
+ */
65
+ export class ERC20Incentive extends DeployableTarget<
66
+ ERC20IncentivePayload,
67
+ typeof erc20IncentiveAbi
68
+ > {
69
+ public override readonly abi = erc20IncentiveAbi;
70
+ /**
71
+ * @inheritdoc
72
+ *
73
+ * @public
74
+ * @static
75
+ * @type {Address}
76
+ */
77
+ public static override base: Address = import.meta.env
78
+ .VITE_ERC20_INCENTIVE_BASE;
79
+ /**
80
+ * @inheritdoc
81
+ *
82
+ * @public
83
+ * @static
84
+ * @type {RegistryType}
85
+ */
86
+ public static override registryType: RegistryType = RegistryType.INCENTIVE;
87
+
88
+ /**
89
+ * The owner of the incentive
90
+ *
91
+ * @public
92
+ * @async
93
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'owner'>} [params]
94
+ * @returns {unknown}
95
+ */
96
+ public async owner(params?: ReadParams<typeof erc20IncentiveAbi, 'owner'>) {
97
+ return readErc20IncentiveOwner(this._config, {
98
+ address: this.assertValidAddress(),
99
+ args: [],
100
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
101
+ ...(params as any),
102
+ });
103
+ }
104
+
105
+ /**
106
+ * Calculates the current reward based on the time since the last claim. The reward is calculated based on the time since the last claim, the available budget, and the reward parameters. It increases linearly over time in the absence of claims, with each hour adding `rewardBoost` to the current reward, up to the available budget. For example, if there is one claim in the first hour, then no claims for three hours, the claimable reward would be `initialReward - rewardDecay + (rewardBoost * 3)`
107
+ *
108
+ * @public
109
+ * @async
110
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'currentReward'>} [params]
111
+ * @returns {Promise<bigint>} - The current reward
112
+ */
113
+ public async currentReward(
114
+ params?: ReadParams<typeof erc20IncentiveAbi, 'currentReward'>,
115
+ ) {
116
+ return readErc20IncentiveCurrentReward(this._config, {
117
+ address: this.assertValidAddress(),
118
+ args: [],
119
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
120
+ ...(params as any),
121
+ });
122
+ }
123
+
124
+ /**
125
+ * The number of claims that have been made
126
+ *
127
+ * @public
128
+ * @async
129
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'claims'>} [params]
130
+ * @returns {Promise<bigint>}
131
+ */
132
+ public async claims(params?: ReadParams<typeof erc20IncentiveAbi, 'claims'>) {
133
+ return readErc20IncentiveClaims(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
+ * A mapping of address to claim status
143
+ *
144
+ * @public
145
+ * @async
146
+ * @param {Address} address
147
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'claimed'>} [params]
148
+ * @returns {Promise<boolean>}
149
+ */
150
+ public async claimed(
151
+ address: Address,
152
+ params?: ReadParams<typeof erc20IncentiveAbi, 'claimed'>,
153
+ ) {
154
+ return readErc20IncentiveClaimed(this._config, {
155
+ address: this.assertValidAddress(),
156
+ args: [address],
157
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
158
+ ...(params as any),
159
+ });
160
+ }
161
+
162
+ /**
163
+ * The address of the ERC20-like token
164
+ *
165
+ * @public
166
+ * @async
167
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'asset'>} [params]
168
+ * @returns {Promise<Address>}
169
+ */
170
+ public async asset(params?: ReadParams<typeof erc20IncentiveAbi, 'asset'>) {
171
+ return readErc20IncentiveAsset(this._config, {
172
+ address: this.assertValidAddress(),
173
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
174
+ ...(params as any),
175
+ });
176
+ }
177
+
178
+ /**
179
+ * The strategy for the incentive (MINT or POOL)
180
+ *
181
+ * @public
182
+ * @async
183
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'strategy'>} [params]
184
+ * @returns {Promise<StrategyType>}
185
+ */
186
+ public async strategy(
187
+ params?: ReadParams<typeof erc20IncentiveAbi, 'strategy'>,
188
+ ): Promise<StrategyType> {
189
+ return readErc20IncentiveStrategy(this._config, {
190
+ address: this.assertValidAddress(),
191
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
192
+ ...(params as any),
193
+ }) as Promise<StrategyType>;
194
+ }
195
+
196
+ /**
197
+ * The reward amount issued for each claim
198
+ *
199
+ * @public
200
+ * @async
201
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'reward'>} [params]
202
+ * @returns {Promise<bigint>}
203
+ */
204
+ public async reward(params?: ReadParams<typeof erc20IncentiveAbi, 'reward'>) {
205
+ return readErc20IncentiveReward(this._config, {
206
+ address: this.assertValidAddress(),
207
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
208
+ ...(params as any),
209
+ });
210
+ }
211
+
212
+ /**
213
+ * The limit (max claims, or max entries for raffles)
214
+ *
215
+ * @public
216
+ * @async
217
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'limit'>} [params]
218
+ * @returns {unknown}
219
+ */
220
+ public async limit(params?: ReadParams<typeof erc20IncentiveAbi, 'limit'>) {
221
+ return readErc20IncentiveLimit(this._config, {
222
+ address: this.assertValidAddress(),
223
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
224
+ ...(params as any),
225
+ });
226
+ }
227
+
228
+ /**
229
+ * The set of addresses that have claimed a slot in the incentive raffle, accessed by bigint index.
230
+ *
231
+ * @public
232
+ * @async
233
+ * @param {bigint} i - Index of address
234
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'entries'>} [params]
235
+ * @returns {Promise<Address>}
236
+ */
237
+ public async entries(
238
+ i: bigint,
239
+ params?: ReadParams<typeof erc20IncentiveAbi, 'entries'>,
240
+ ) {
241
+ return readErc20IncentiveEntries(this._config, {
242
+ address: this.assertValidAddress(),
243
+ args: [i],
244
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
245
+ ...(params as any),
246
+ });
247
+ }
248
+
249
+ /**
250
+ * Claim the incentive
251
+ *
252
+ * @public
253
+ * @async
254
+ * @param {ClaimPayload} payload
255
+ * @param {?WriteParams<typeof erc20IncentiveAbi, 'claim'>} [params]
256
+ * @returns {Promise<boolean>} - Returns true if successfully claimed
257
+ */
258
+ public async claim(
259
+ payload: ClaimPayload,
260
+ params?: WriteParams<typeof erc20IncentiveAbi, 'claim'>,
261
+ ) {
262
+ return this.awaitResult(this.claimRaw(payload, params));
263
+ }
264
+
265
+ /**
266
+ * Claim the incentive
267
+ *
268
+ * @public
269
+ * @async
270
+ * @param {ClaimPayload} payload
271
+ * @param {?WriteParams<typeof erc20IncentiveAbi, 'claim'>} [params]
272
+ * @returns {Promise<boolean>} - Returns true if successfully claimed
273
+ */
274
+ public async claimRaw(
275
+ payload: ClaimPayload,
276
+ params?: WriteParams<typeof erc20IncentiveAbi, 'claim'>,
277
+ ) {
278
+ const { request, result } = await simulateErc20IncentiveClaim(
279
+ this._config,
280
+ {
281
+ address: this.assertValidAddress(),
282
+ args: [prepareClaimPayload(payload)],
283
+ ...this.optionallyAttachAccount(),
284
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
285
+ ...(params as any),
286
+ },
287
+ );
288
+ const hash = await writeErc20IncentiveClaim(this._config, request);
289
+ return { hash, result };
290
+ }
291
+
292
+ /**
293
+ * Clawback assets from the incentive
294
+ *
295
+ * @public
296
+ * @async
297
+ * @param {ClaimPayload} payload
298
+ * @param {?WriteParams<typeof erc20IncentiveAbi, 'clawback'>} [params]
299
+ * @returns {Promise<boolean>} - True if the assets were successfully clawbacked
300
+ */
301
+ public async clawback(
302
+ payload: ClaimPayload,
303
+ params?: WriteParams<typeof erc20IncentiveAbi, 'clawback'>,
304
+ ) {
305
+ return this.awaitResult(this.clawbackRaw(payload, params));
306
+ }
307
+
308
+ /**
309
+ * Clawback assets from the incentive
310
+ *
311
+ * @public
312
+ * @async
313
+ * @param {ClaimPayload} payload
314
+ * @param {?WriteParams<typeof erc20IncentiveAbi, 'clawback'>} [params]
315
+ * @returns {Promise<boolean>} - True if the assets were successfully clawbacked
316
+ */
317
+ public async clawbackRaw(
318
+ payload: ClaimPayload,
319
+ params?: WriteParams<typeof erc20IncentiveAbi, 'clawback'>,
320
+ ) {
321
+ const { request, result } = await simulateErc20IncentiveClawback(
322
+ this._config,
323
+ {
324
+ address: this.assertValidAddress(),
325
+ args: [prepareClaimPayload(payload)],
326
+ ...this.optionallyAttachAccount(),
327
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
328
+ ...(params as any),
329
+ },
330
+ );
331
+ const hash = await writeErc20IncentiveClawback(this._config, request);
332
+ return { hash, result };
333
+ }
334
+
335
+ /**
336
+ * 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.
337
+ *
338
+ * @public
339
+ * @async
340
+ * @param {ClaimPayload} payload
341
+ * @param {?ReadParams<typeof erc20IncentiveAbi, 'isClaimable'>} [params]
342
+ * @returns {unknown} = True if the incentive is claimable based on the data payload
343
+ */
344
+ public async isClaimable(
345
+ payload: ClaimPayload,
346
+ params?: ReadParams<typeof erc20IncentiveAbi, 'isClaimable'>,
347
+ ) {
348
+ return readErc20IncentiveIsClaimable(this._config, {
349
+ address: this.assertValidAddress(),
350
+ args: [prepareClaimPayload(payload)],
351
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
352
+ ...(params as any),
353
+ });
354
+ }
355
+
356
+ /**
357
+ * Draw a winner from the raffle. Only callable by owner. Only valid when the strategy is set to `Strategy.RAFFLE`
358
+ *
359
+ * @public
360
+ * @async
361
+ * @param {?WriteParams<typeof erc20IncentiveAbi, 'drawRaffle'>} [params]
362
+ * @returns {Promise<void>}
363
+ */
364
+ public async drawRaffle(
365
+ params?: WriteParams<typeof erc20IncentiveAbi, 'drawRaffle'>,
366
+ ) {
367
+ return this.awaitResult(this.drawRaffleRaw(params));
368
+ }
369
+
370
+ /**
371
+ * Draw a winner from the raffle. Only callable by owner. Only valid when the strategy is set to `Strategy.RAFFLE`
372
+ *
373
+ * @public
374
+ * @async
375
+ * @param {?WriteParams<typeof erc20IncentiveAbi, 'drawRaffle'>} [params]
376
+ * @returns {Promise<void>}
377
+ */
378
+ public async drawRaffleRaw(
379
+ params?: WriteParams<typeof erc20IncentiveAbi, 'drawRaffle'>,
380
+ ) {
381
+ const { request, result } = await simulateErc20IncentiveDrawRaffle(
382
+ this._config,
383
+ {
384
+ address: this.assertValidAddress(),
385
+ ...this.optionallyAttachAccount(),
386
+ // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
387
+ ...(params as any),
388
+ },
389
+ );
390
+ const hash = await writeErc20IncentiveDrawRaffle(this._config, request);
391
+ return { hash, result };
392
+ }
393
+
394
+ /**
395
+ * @inheritdoc
396
+ *
397
+ * @public
398
+ * @param {?ERC20IncentivePayload} [_payload]
399
+ * @param {?DeployableOptions} [_options]
400
+ * @returns {GenericDeployableParams}
401
+ */
402
+ public override buildParameters(
403
+ _payload?: ERC20IncentivePayload,
404
+ _options?: DeployableOptions,
405
+ ): GenericDeployableParams {
406
+ const [payload, options] = this.validateDeploymentConfig(
407
+ _payload,
408
+ _options,
409
+ );
410
+ return {
411
+ abi: erc20IncentiveAbi,
412
+ bytecode: bytecode as Hex,
413
+ args: [prepareERC20IncentivePayload(payload)],
414
+ ...this.optionallyAttachAccount(options.account),
415
+ };
416
+ }
417
+ }
@@ -0,0 +1,156 @@
1
+ import {
2
+ readMockErc20BalanceOf,
3
+ readMockErc20TotalSupply,
4
+ } from '@boostxyz/evm';
5
+ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
6
+ import { signMessage } from '@wagmi/core';
7
+ import {
8
+ encodeAbiParameters,
9
+ encodePacked,
10
+ isAddress,
11
+ keccak256,
12
+ pad,
13
+ parseEther,
14
+ zeroAddress,
15
+ } from 'viem';
16
+ import { toHex } from 'viem';
17
+ import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
18
+ import { accounts } from '../../test/accounts';
19
+ import {
20
+ type BudgetFixtures,
21
+ type Fixtures,
22
+ defaultOptions,
23
+ deployFixtures,
24
+ freshBoost,
25
+ fundBudget,
26
+ } from '../../test/helpers';
27
+ import {
28
+ StrategyType,
29
+ prepareClaimPayload,
30
+ prepareSignerValidatorClaimDataPayload,
31
+ } from '../utils';
32
+ import { ERC20VariableIncentive } from './ERC20VariableIncentive';
33
+
34
+ const BOOST_CORE_CLAIM_FEE = parseEther('0.000075');
35
+
36
+ let fixtures: Fixtures, budgets: BudgetFixtures;
37
+
38
+ describe('ERC20VariableIncentive', () => {
39
+ beforeAll(async () => {
40
+ fixtures = await loadFixture(deployFixtures);
41
+ });
42
+
43
+ beforeEach(async () => {
44
+ budgets = await loadFixture(fundBudget(defaultOptions, fixtures));
45
+ });
46
+
47
+ test('can successfully be deployed', async () => {
48
+ const action = new ERC20VariableIncentive(defaultOptions, {
49
+ asset: zeroAddress,
50
+ reward: 1n,
51
+ limit: 1n,
52
+ });
53
+ await action.deploy();
54
+ expect(isAddress(action.assertValidAddress())).toBe(true);
55
+ });
56
+
57
+ test('can claim', async () => {
58
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
59
+ const referrer = accounts.at(1)!.account!,
60
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
61
+ trustedSigner = accounts.at(0)!;
62
+ const erc20VariableIncentive = new fixtures.bases.ERC20VariableIncentive(
63
+ defaultOptions,
64
+ {
65
+ asset: budgets.erc20.assertValidAddress(),
66
+ reward: 1n,
67
+ limit: 1n,
68
+ },
69
+ );
70
+ const boost = await freshBoost(fixtures, {
71
+ budget: budgets.budget,
72
+ incentives: [erc20VariableIncentive],
73
+ });
74
+
75
+ const claimant = trustedSigner.account;
76
+ const incentiveQuantity = 1;
77
+ const claimDataPayload = await prepareSignerValidatorClaimDataPayload({
78
+ signer: trustedSigner,
79
+ incentiveData: encodeAbiParameters(
80
+ [{ name: '', type: 'uint256' }],
81
+ [parseEther('1')],
82
+ ),
83
+ chainId: defaultOptions.config.chains[0].id,
84
+ validator: boost.validator.assertValidAddress(),
85
+ incentiveQuantity,
86
+ claimant,
87
+ boostId: boost.id,
88
+ });
89
+ await fixtures.core.claimIncentive(
90
+ boost.id,
91
+ 0n,
92
+ referrer,
93
+ claimDataPayload,
94
+ { value: BOOST_CORE_CLAIM_FEE },
95
+ );
96
+ expect(
97
+ await readMockErc20BalanceOf(defaultOptions.config, {
98
+ address: budgets.erc20.assertValidAddress(),
99
+ args: [claimant],
100
+ }),
101
+ ).toBe(1n);
102
+ });
103
+
104
+ test('cannot claim twice', async () => {
105
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
106
+ const referrer = accounts.at(1)!.account!;
107
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
108
+ const trustedSigner = accounts.at(0)!;
109
+ const erc20VariableIncentive = new fixtures.bases.ERC20VariableIncentive(
110
+ defaultOptions,
111
+ {
112
+ asset: budgets.erc20.assertValidAddress(),
113
+ reward: 1n,
114
+ limit: 1n,
115
+ },
116
+ );
117
+ const boost = await freshBoost(fixtures, {
118
+ budget: budgets.budget,
119
+ incentives: [erc20VariableIncentive],
120
+ });
121
+
122
+ const claimant = trustedSigner.account;
123
+ const incentiveQuantity = 1;
124
+ const claimDataPayload = await prepareSignerValidatorClaimDataPayload({
125
+ signer: trustedSigner,
126
+ incentiveData: encodeAbiParameters(
127
+ [{ name: '', type: 'uint256' }],
128
+ [parseEther('1')],
129
+ ),
130
+ chainId: defaultOptions.config.chains[0].id,
131
+ validator: boost.validator.assertValidAddress(),
132
+ incentiveQuantity,
133
+ claimant,
134
+ boostId: boost.id,
135
+ });
136
+
137
+ await fixtures.core.claimIncentive(
138
+ boost.id,
139
+ 0n,
140
+ referrer,
141
+ claimDataPayload,
142
+ { value: BOOST_CORE_CLAIM_FEE },
143
+ );
144
+ try {
145
+ await fixtures.core.claimIncentive(
146
+ boost.id,
147
+ 0n,
148
+ referrer,
149
+ claimDataPayload,
150
+ { value: BOOST_CORE_CLAIM_FEE },
151
+ );
152
+ } catch (e) {
153
+ expect(e).toBeInstanceOf(Error);
154
+ }
155
+ });
156
+ });