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